home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / text / docs / arexx.lha / arexx.doc
Text File  |  1992-12-02  |  282KB  |  12,022 lines

  1.  
  2.   South West Amiga Group  Presents: Introduction To ARexx     30th March 1991
  3.  
  4.  
  5.  
  6. Welcome to ARexx,an implementation of the REXX language for the Amiga computer.
  7.  
  8. ARexx is a powerful programming tool,but because of its clean syntax and
  9.  
  10. sparse vocabulary is also easy to learn and easy to use.
  11.  
  12.  
  13.  
  14.  
  15.  
  16. This tutorial will attempt to give an insight of the apparent ease that ARexx
  17.  
  18. may be used. The chapters that follow have been organised to provide a gentle
  19.  
  20. introduction to the language.
  21.  
  22.  
  23.  
  24. Chapter 1,What is ARexx?,gives an overview of the ARexx language and its
  25.  
  26. implementation of the Amiga.
  27.  
  28.  
  29.  
  30. Chapter 2,Getting Acquainted,tells how to install ARexx on your Amiga and
  31.  
  32. presents several example programs to illustrate the features of the language.
  33.  
  34.  
  35.  
  36. Chapter 3,Elements of the Language,introduces the language structure and
  37.  
  38. syntax.
  39.  
  40.  
  41.  
  42. Chapter 4,Instructions,describes the action statements of ARexx.
  43.  
  44.  
  45.  
  46. Chapter 5,Commands,describes the program statements used to communicate with
  47.  
  48. external programs.
  49.  
  50.  
  51.  
  52. Chapter 6,Functions,explains how functions are called and documents the Built-
  53.  
  54. In Function library.
  55.  
  56.  
  57.  
  58. Chapter 7,Tracing and Interrupts,describes the source level debugging features
  59.  
  60. useful for developing and testing programs.
  61.  
  62.  
  63.  
  64. Chapter 8,Parsing and Templates,describes the instructions used to extract
  65.  
  66. words or fields from strings.
  67.  
  68.  
  69.  
  70. Chapter 9,The Resident Process,describes the capabilities of the global
  71.  
  72. communications and resources manager.
  73.  
  74.  
  75.  
  76. Chapter 10,Interfacing to ARexx,describes how to design and implement an
  77.  
  78. interface between ARexx and an external program.
  79.  
  80.  
  81.  
  82. Appendix A,Error Messages,lists the error messages issued by the interpreter.
  83.  
  84.  
  85.  
  86. Appendix B,Limits and Compatibility,discusses the compatibility of ARexx with
  87.  
  88. the language standard.
  89.  
  90.  
  91.  
  92. Appendix C,The ARexx Systems Library,documents the functions of ARexx systems
  93.  
  94. library.
  95.  
  96.  
  97.  
  98. Appendix D,The Support Library,documents the library of Amiga specific
  99.  
  100. functions.
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.                                 1
  109.  
  110.  
  111.  
  112. USING THIS TUTORIAL
  113.  
  114.  
  115.  
  116. If you are new to the REXX language,or perhaps to programming itself,you should
  117.  
  118. review chapters 1 through 4 and then play with ARexx by running some of the
  119.  
  120. sample programs given in chapter 2. Further examples are available in the arexx
  121.  
  122. drawer of the ARexx Tutorial disk.
  123.  
  124.  
  125.  
  126. If you are already familiar with REXX you may wish to skip directly to chapter
  127.  
  128. 5,which begins to present some of the system-dependent features of this
  129.  
  130. implementation. A summary of the compatibility of ARexx with the language
  131.  
  132. definition is contained in Appendix B.
  133.  
  134.  
  135.  
  136. TYPOGRAPHIC CONVENTIONS
  137.  
  138.  
  139.  
  140. Describing a language is sometimes difficult because of the multiple and
  141.  
  142. changing contexts involved. To help clarify the presentation here,a simply
  143.  
  144. typographic convention has been adopted throughout the document. All of the
  145.  
  146. terms and words specific to the REXX language,as well as the program examples
  147.  
  148. and computer input and output,have been set in typewriter font like this. This
  149.  
  150. should help to distinguish the language keywords and examples from the
  151.  
  152. surrounding text.
  153.  
  154.  
  155.  
  156. 2 FUTURE DIRECTIONS
  157.  
  158.  
  159.  
  160. ARexx,like most software products,will probably evolve somewhat over the next
  161.  
  162. few years as new features are added,old bugs are removed,and market imperatives
  163.  
  164. become more apparant. While the core language will probably undergo few
  165.  
  166. modifications,many capabilities will be added to the function libraries
  167.  
  168. supported by ARexx. Your comments and suggestions for improvements to ARexx are
  169.  
  170. most welcome.
  171.  
  172.  
  173.  
  174. The author sincerely hopes that other software developers will consider using
  175.  
  176. ARexx with their products. The advantages of having a rich variety of software
  177.  
  178. products sharing a common user interface and a common procedural interface
  179.  
  180. cannot be overstated. This is the underlying promise of the Amiga's
  181.  
  182. multitasking capability,and that which most sets it apart from other
  183.  
  184. inexpensive computers.
  185.  
  186.  
  187.  
  188. Example Programs. One of the best ways to learn a computer language is to study
  189.  
  190. examples written by more experienced programmers. The ARexx Tutorial disk
  191.  
  192. includes a few example programs in the arexx drawer,and more programs will be
  193.  
  194.  added in future releases.
  195.  
  196.  
  197.  
  198. If you have written REXX language program(for any computer)that you think would
  199.  
  200. be of interest to a more general audience,please send it to Fred Fish PD for
  201.  
  202. consideration. Programs should be of interest either in terms of their specific
  203.  
  204. funtionality or as an example of programming technique. Each program submitted
  205.  
  206. should include an author credit and a few lines of commentary on its intended
  207.  
  208. fuction.
  209.  
  210.  
  211.  
  212.                                 2
  213.  
  214.  
  215.  
  216. ARexx is a high-level language useful for prototyping,software integration,and
  217.  
  218. general programming tasks. It is an implementation of the REXX language
  219.  
  220. described by M.F. Cowlishaw in The REXX Language:A Practical Approach to
  221.  
  222. Programming(Prentice-Hall,1985),and follow the language definition closely.
  223.  
  224. ARexx is particularly well suited as a command language. Command programs,
  225.  
  226. sometimes called "scripts" or "macros",are widely used to extend the predefined
  227.  
  228. commands of an operating system or to customize an applications program.
  229.  
  230.  
  231.  
  232. As a programming language,ARexx can be useful to a wide cross section of users.
  233.  
  234. For the novice programmer,ARexx is an easy-to-learn yet powerful language that
  235.  
  236. serves as a good introduction to programming techniques. Its source-level
  237.  
  238. debugging facilities will help take some of the mystery out of how programs
  239.  
  240. work(or don't work,as is more frequently the case.)
  241.  
  242.  
  243.  
  244. For the more sophisticated user,ARexx provides the means to build fully
  245.  
  246. integrated software packages,combining different applications programs into an
  247.  
  248. environment tailored to their needs. A common command language among
  249.  
  250. applications that support ARexx will bring uniformity to procedural interfaces,
  251.  
  252. much as the Amiga's Intuition provides uniformity in the graphical interface.
  253.  
  254.  
  255.  
  256. Finally,for the software developer,ARexx offers a straightforward way to build
  257.  
  258. fully programmable applications programs. Developers can concentrate their
  259.  
  260. efforts on making the basic operations of their programs fast and efficient,and
  261.  
  262. let the end user add the frills and custom features.
  263.  
  264.  
  265.  
  266. LANGUAGE FEATURES
  267.  
  268.  
  269.  
  270. Some of the important features of the language are:
  271.  
  272.  
  273.  
  274. TYPELESS DATA. Data are treated as typeless character strings. Variables do not
  275.  
  276. have to be declared before being used,and all operations dynamically check the
  277.  
  278. validity of the operands.
  279.  
  280.  
  281.  
  282. COMMAND INTERFACE. ARexx programs can issue commands to external programs that
  283.  
  284. provide a suitable command interface. Any software package that implements the
  285.  
  286. command interface is then fully programmable using ARexx,and can be extended
  287.  
  288. and customized by the end user.
  289.  
  290.  
  291.  
  292. TRACING AND DEBUGGING. ARexx includes source-level debugging facilities that
  293.  
  294. allow the programmer to see the step-by-step actions of a program as it runs,
  295.  
  296. thereby reducing the time required to develop and test programs. An internal
  297.  
  298. interrupt system permits special handling of errors that would otherwise cause
  299.  
  300. the program to terminate.
  301.  
  302.  
  303.  
  304.                                 3
  305.  
  306.  
  307.  
  308. INTERPRETED EXECUTION. ARexx programs are run by an interpreter,so separate
  309.  
  310. compilation and linking steps are not required. This makes it especially useful
  311.  
  312. for prototyping and as a learning tool.
  313.  
  314.  
  315.  
  316. FUNCTION LIBRARIES. External function libraries can be used to extend the
  317.  
  318. capabilities of the language or as bridges to other programs. Libraries also
  319.  
  320. allow ARexx programs to be used as "test drivers" for software development and
  321.  
  322. testing.
  323.  
  324.  
  325.  
  326. AUTOMATIC RESOURCE MANAGEMENT. Internal memory allocation related to the
  327.  
  328. creation and destruction of strings and other data structures are handled
  329.  
  330. automatically.
  331.  
  332.  
  333.  
  334. AREXX ON THE AMIGA
  335.  
  336.  
  337.  
  338. ARexx was designed to run on the Amiga,and makes use of many of the features of
  339.  
  340. its multitasking operating system. ARexx programs run as separate tasks and
  341.  
  342. may communicate with each other or with external programs. The interpreter
  343.  
  344. follows the design guidelines expected of well-behaved programs in a
  345.  
  346. multitasking environment: specifcally,it uses as little memory as possible and
  347.  
  348. is careful to reutrn resources to the operating system when they are no longer
  349.  
  350. needed. Memory requirements were minimized by implementing the entire ARexx
  351.  
  352. system as a shared library,so that only one copy of the program code must be
  353.  
  354. loaded.
  355.  
  356.  
  357.  
  358.  
  359.  
  360.                                 4
  361.  
  362.  
  363.  
  364.                          GETTING ACQUAINTED
  365.  
  366.  
  367.  
  368. This chapter explains how to install ARexx on your Amiga computer and shows
  369.  
  370. some example programs.
  371.  
  372.  
  373.  
  374. INSTALLING AREXX
  375.  
  376.  
  377.  
  378. ARexx requires an Amiga computer with at least 256k of memory,and will operate
  379.  
  380. under V1.2 or V1.3 of the operating system. It uses the double-precision math
  381.  
  382. library called "mathieeedoubbas.library" that is supplied with the Amiga
  383.  
  384. WorkBench disk,so make sure that this file is present in your LIBS: directory.
  385.  
  386. The Tutorial disk includes the language system,some example programs,and a
  387.  
  388. set of the INCLUDE files required for integrating ARexx with other software
  389.  
  390. packages.
  391.  
  392.  
  393.  
  394. AREXX AND WORKBENCH
  395.  
  396.  
  397.  
  398. ARexx can be installed and loaded from within the icon-based environment
  399.  
  400. provided by the Amiga WorkBench. However,it is a primarily a text-oriented
  401.  
  402. language system and requires a good text editor and file management environment
  403.  
  404. to be most effective. Unless you purchased ARexx as part of an applications
  405.  
  406. package that includes an integrated editor,you'll probably find it useful to
  407.  
  408. become familiar with the Commmand Line Interface (CLI)environment on the Amiga.
  409.  
  410.  
  411.  
  412. INSTALLATION
  413.  
  414.  
  415.  
  416. The ARexx language system consists of a shared library,a resident program,and
  417.  
  418. several command utilities. All of the required files are contained in the :c
  419.  
  420. and :libs directories of the Tutorial disk. ARexx may be installed on any of
  421.  
  422. the system disks with which it will be used,but first check the :c and :libs
  423.  
  424. directores of each disk to make sure that there are no naming conflicts.
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.                                 5
  433.  
  434.  
  435.  
  436. 1. Activate a CLI window.
  437.  
  438. 2. Insert the Tutorial disk into drive 0 and type "df0:rxinstall".
  439.  
  440. 3. At the program prompt,insert the system disk on which ARexx is to be
  441.  
  442. installed into drive 0.
  443.  
  444. 4. Repeat step 3 as required.
  445.  
  446.  
  447.  
  448. STARTING THE RESIDENT PROCESS
  449.  
  450.  
  451.  
  452. ARexx programs are launched by a background program called the resident
  453.  
  454. process. It can be started by issuing the command rexxmast and must be active
  455.  
  456. before any ARexx programs can be run. The rexxmast program briefly displays a
  457.  
  458. small window to announce itself,and then disappears into the background to
  459.  
  460. await your next request. If you will be using ARexx frequently,you can place
  461.  
  462. the rexxmast command in the "startup-sequence" file that resides in the system
  463.  
  464. S: directory. This will start the resident process automatically when you
  465.  
  466. reboot the computer.
  467.  
  468.  
  469.  
  470. After the resident process has been loaded,ARexx programs can be run from the
  471.  
  472. CLI by typing the command rx followed by the program name and any arguments.
  473.  
  474. For example,the sample program Stars.rexx,could be run by typing "rx :rexx/stars
  475.    ."
  476.  
  477.  
  478.  
  479. You may not need to start up the resident process if you are using a software
  480.  
  481. package that starts it automatically. Applications that use ARexx can test
  482.  
  483. whether the resident process is active by checking for a public message port
  484.  
  485. named "REXX." If the port hasn't been opened,the program can issue the rexxmast
  486.  
  487. command directly.
  488.  
  489.  
  490.  
  491. The resident process can be closed using the command rxc;it will then exit as
  492.  
  493. soon as the last ARexx program finishes execution. Unless you are very short on
  494.  
  495. memory space,there is usually no reason to close ARexx,as it simply waits in
  496.  
  497. the background for the next program to run.
  498.  
  499.  
  500.  
  501. NAMING CONVENTIONS
  502.  
  503.  
  504.  
  505. ARexx programs can be named anything,but adopting a simple naming convention
  506.  
  507. will make managing the programs much easier. Programs to be run from the CLI
  508.  
  509. are usually given the file extention .rexx to distinguish them from programs
  510.  
  511. written in other languages. Programs written as "macros" or "scripts" for a
  512.  
  513. particular applications program should be given a file extension specific to
  514.  
  515. that program. For example,a macro written for a communications program called
  516.  
  517. "MyComm" might be named "download.myc". ARexx uses this file extention when it
  518.  
  519. searches for a program file to be executed.
  520.  
  521.  
  522.  
  523. THE REXX: DIRECTORY
  524.  
  525.  
  526.  
  527. You can designate one directory as the system-wide source for ARexx programs by
  528.  
  529. defining a REXX: "device" with the assign command. This directory should reside
  530.  
  531. on a volume that is usually mounted,such as SYS: or a hard disk. For example,
  532.  
  533. the command "assign rexx: sys:rexx" defines the REXX: device as the :rexx
  534.  
  535. directory on the system disk. Once defined,the REXX: device is searched after
  536.  
  537. the current directory when looking for an ARexx program.
  538.  
  539.  
  540.  
  541.                                 6
  542.  
  543.  
  544.  
  545. PROGRAM EXAMPLES
  546.  
  547.  
  548.  
  549. Before introducing the structure and syntax of the language,let's look at a few
  550.  
  551. examples of ARexx programs. Readers familiar with other high-level programming
  552.  
  553. languages should find many points of similarity between ARexx and other
  554.  
  555. languages. In the examples that follow,new terms are highlighted in the text as
  556.  
  557. they are introduced,and will be convered in depth in the next few chapters.
  558.  
  559.  
  560.  
  561. These short programs can be created using any text editor and then run from the
  562.  
  563. Command Line Interface (CLI),or may simply be read as samples of the language.
  564.  
  565. If the examples are to be run,first complete the installation procedures
  566.  
  567. outlined in the previous section,and then start the ARexx resident process.
  568.  
  569. Example programs can then be run by entering,for example,"rx age" at the CLI
  570.  
  571. prompt.
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.         /* A simple program */
  580.  
  581.         say 'Hello,World'
  582.  
  583.  
  584.  
  585. This program consists of a comment line that describes the program and an
  586.  
  587. instruction that displays text on the console. For historical reasons, ARexx
  588.  
  589. programs begin with a comment line;the initial "/*" says "I'm an ARexx program"
  590.  
  591. to the interpreter when it searches for a program.
  592.  
  593.  
  594.  
  595. Instructions are language statements that denote a certain action to be
  596.  
  597. performed,and always start with a symbol,in this case the word say. Symbols are
  598.  
  599. translated to uppercase when the program is run,so the symbol say here is
  600.  
  601. equivalent to SAY. Following say is an example of a string,which is a series of
  602.  
  603. characters surrounded by quotes ('). Double quotes (") could also have been
  604.  
  605. used to define the string.
  606.  
  607.  
  608.  
  609. In the next program we'll display a prompt for input and then read some
  610.  
  611. information from the user.
  612.  
  613.  
  614.  
  615.         /* Calculate age in days */
  616.  
  617.         say 'Please enter your age'
  618.  
  619.         pull age
  620.  
  621.         say 'You are about' age*365 'days old'
  622.  
  623.  
  624.  
  625. This program uses the pull instruction to read a line of input into a variable
  626.  
  627. called age,which is then used with a say instuction. Variables are symbols that
  628.  
  629. may be assigned a value. The words following say form an expression in which
  630.  
  631. strings are joined and an arithmetic calculation is performed.
  632.  
  633.  
  634.  
  635. Note that the variable age did not have to be declared as a number;instead,its
  636.  
  637. value was checked when it was actually used in the expression. To see what
  638.  
  639. would happen if age wasn't a number,try rerunning the program with a
  640.  
  641. non-numeric entry for the age. The resulting error message shows the line
  642.  
  643. number and type of error that occurred,after which the program ends.
  644.  
  645.  
  646.  
  647.                                 7
  648.  
  649.  
  650.  
  651. The next program introduces the do instruction,which allows program statements
  652.  
  653. to be executed repeatedly. It also illustrates the exponentiation operator,
  654.  
  655. which is used to raise a number to an integral power.
  656.  
  657.  
  658.  
  659.         /* Calculate some squares and cubes      */
  660.  
  661.         do i = 1 to 10      /* 10 interations    */
  662.  
  663.            say i i**2 i**3  /* calculations      */
  664.  
  665.            end
  666.  
  667.         say ' all done '
  668.  
  669.  
  670.  
  671. The do instruction causes the statements between the do and end instructions to
  672.  
  673. be executed 10 times. The variable i is the index variable for the loop,and is
  674.  
  675. incremented by 1 for each iteration. The number following the symbol to is the
  676.  
  677. limit for the do instruction,and could have been a full expression rather than
  678.  
  679. just the constant 10. Note that the statements within the loop have been
  680.  
  681. indented. This is not required by the language,but it makes the program more
  682.  
  683. readable and is therefore good programming practice.
  684.  
  685.  
  686.  
  687. The subject of the next example is the if instruction,a often-used control
  688.  
  689. statement that allows statements to be conditionally executed. The numbers from
  690.  
  691. 1 to 10 are classified as even or odd by dividing them by 2 and then checking
  692.  
  693. the remainder.
  694.  
  695.  
  696.  
  697.         /* Even or odd? */
  698.  
  699.         do i = 1 to 10
  700.  
  701.            if i//2 = 0 then type = 'even'
  702.  
  703.                        else type = 'odd'
  704.  
  705.            say i 'is' type
  706.  
  707.            end
  708.  
  709.  
  710.  
  711. This example intoduces the // arithmetic operator,which calculates the
  712.  
  713. remainder after a division operation. The if instruction tests whether the
  714.  
  715. remainder is 0 and executes the then branch if it is,thereby setting the
  716.  
  717. variable type to "even." If the remainder was not 0,the alternative else branch
  718.  
  719. is executed and type is set to "odd."
  720.  
  721.  
  722.  
  723. The next example introduces the concept of a function,which is a group of
  724.  
  725. statements that can be executed by mentioning the function name in a suitable
  726.  
  727. context. Functions are an important part of most programming languages,as they
  728.  
  729. allow large,complex programs to be built from smaller modules. Functions are
  730.  
  731. specified in an expression as a name followed by an open parenthesis. One or
  732.  
  733. more expressions called arguments may follow the parenthesis;these are used to
  734.  
  735. pass information to the function for processing.
  736.  
  737.  
  738.  
  739.                                 8
  740.  
  741.  
  742.  
  743.         /* Defining and calling a function     */
  744.  
  745.         do i = 1 to 5
  746.  
  747.            say i square(i)     /* call square  */
  748.  
  749.            end
  750.  
  751.         exit            /* all done            */
  752.  
  753.         square:         /* function name       */
  754.  
  755.         arg x           /* get the "argument"  */
  756.  
  757.         return x**2     /* square it and return*/
  758.  
  759.  
  760.  
  761. The function square is defined in the lines followed the label square: up
  762.  
  763. through the return instruction. Two new instructions are introduced here: arg
  764.  
  765. retrieves the value of the argument string,and return passes the functon's
  766.  
  767. result back to the point where the function was called.
  768.  
  769.  
  770.  
  771. One final example will suffice for now. A new instruction called trace is used
  772.  
  773. here to activate the tracing features of ARexx.
  774.  
  775.  
  776.  
  777.         /* Demonstrate "results" tracing */
  778.  
  779.         trace results
  780.  
  781.         sum=0;sumsq=0;
  782.  
  783.         do i = 1 to 5
  784.  
  785.            sum = sum + i
  786.  
  787.            sumsq = sumsq + i**2
  788.  
  789.            end
  790.  
  791.         say 'sum=' sum 'sumsq=' sumsq
  792.  
  793.  
  794.  
  795. When this program is run,the console displays the source lines as they are
  796.  
  797. excuted,and shows the final results of expressions. This makes it easy to tell
  798.  
  799. what the program is really doing,and helps reduce the time required to develop
  800.  
  801. and test a new program. One minor point is illustrated here: the third line
  802.  
  803. shows two distinct statements separated by a semicolon (;). The semicolon is an
  804.  
  805. example of a special character,characters that have particular meanings within
  806.  
  807. ARexx programs.
  808.  
  809.  
  810.  
  811. The following chapters will present further information on the language
  812.  
  813. statements illustrated here and will introduce others that have not been shown.
  814.  
  815. Take heart,though;ARexx is a "small" language and there are relatively few
  816.  
  817. words and rules to learn.
  818.  
  819.  
  820.  
  821.                                 9
  822.  
  823.  
  824.  
  825.  
  826.  
  827.                         ELEMENTS OF THE LANGUAGE
  828.  
  829.  
  830.  
  831. This chapter introduces the rules and concepts that make up the REXX language.
  832.  
  833. The intent is not to present a formalized definition,but rather to convey a
  834.  
  835. practical understanding of how the language elements "fit together" to form
  836.  
  837. programs.
  838.  
  839.  
  840.  
  841. FORMAT
  842.  
  843.  
  844.  
  845. ARexx programs are composed of ASCII characters and may be created using any
  846.  
  847. text editor. No special formatting of the program statements is required or
  848.  
  849. imposed on the programmer.
  850.  
  851.  
  852.  
  853. TOKENS
  854.  
  855.  
  856.  
  857. The smallest distinct entities or "words" of the language are called tokens. A
  858.  
  859. token may be series of characters,as in the symbol MyName,or just a single
  860.  
  861. character like the "+" operator. Tokens can be categorized into comments,
  862.  
  863. symbols,strings,operators,and special characters. Each of these groups are
  864.  
  865. described below.
  866.  
  867.  
  868.  
  869. COMMENT TOKENS
  870.  
  871.  
  872.  
  873. Any group of characters beginning with the sequence "/*" and ending with "*/"
  874.  
  875. defines a comment token. Comments may be placed anywhere in a program and cost
  876.  
  877. little in terms of execution speed,since they are stripped(removed)when the
  878.  
  879. program is first scanned by the interpreter. Comments may be "nested" within
  880.  
  881. one another,but each "/*" must have a matching "*/" in the program.
  882.  
  883. Examples:
  884.  
  885.  
  886.  
  887.         /* Your basic comment       */
  888.  
  889.         /* a  /* nested! */ comment */
  890.  
  891.  
  892.  
  893. SYMBOL TOKENS
  894.  
  895.  
  896.  
  897. Any group of the characters a-z,A-Z,0-9,and .!?$_defines a symbol token.
  898.  
  899. Symbols are translated to uppercase as the program is scanned by the
  900.  
  901. interpreter,so the symbol MyName is equivalent to MYNAME. Four types of symbols
  902.  
  903. are recognized:
  904.  
  905.  
  906.  
  907.         Fixed symbols begin with a digit (0-9) or a period(.).
  908.  
  909.         Simple symbols do not begin with a digit,and do not contain any
  910.  
  911.         periods.
  912.  
  913.         Stem symbols have exactly one period at the end of the symbol name.
  914.  
  915.         Compound symbols include one or more periods in the interior of the
  916.  
  917.         name.
  918.  
  919.  
  920.  
  921. Stems and compound symbols have special properties that make them useful for
  922.  
  923. building arrays and lists.
  924.  
  925.  
  926.  
  927.                                 11
  928.  
  929.  
  930.  
  931. SYMBOLS VALUES. The value used for a fixed symbol is always the symbol name
  932.  
  933. itself(as translated to uppercase.) Simple,stem,and compound symbols are called
  934.  
  935. variables and may be assigned a value;the value used for an uninitialized
  936.  
  937. variable is just the variable name itself.
  938.  
  939. Examples:
  940.  
  941.  
  942.  
  943.         123.45          /*a fixed symbol        */
  944.  
  945.         MyName          /*same as MyName        */
  946.  
  947.         a.              /*a stem symbol         */
  948.  
  949.         a.1.Index       /*a compound symbol     */
  950.  
  951.  
  952.  
  953. STRING TOKENS
  954.  
  955.  
  956.  
  957. A group of characters beginning and ending with a quote (')or double quote(")
  958.  
  959. delimiter defines a string token. The delimiter character itself may be
  960.  
  961. included within the string by a double-delimiter sequence (" or ""). The number
  962.  
  963. of characters in the string is called its length,and a string of length zero is
  964.  
  965. called a null string. A string is treated as a literal in an expression;that
  966.  
  967. is,its value is just the string itself.
  968.  
  969.  
  970.  
  971. Strings followed immediately by an "X" or "B" character that is not part of a
  972.  
  973. longer symbol are classified as hex or binary strings,respectively,and must be
  974.  
  975. composed of hexadecimal digits(0-9,A-F) or binary digits(0,1). Blanks are
  976.  
  977. permitted at byte boundaries for added readability. Hex and binary strings are
  978.  
  979. convenient for specifying non-ASCII characters and for machine-specific
  980.  
  981. information like addresses in a program. They are converted immediately to the
  982.  
  983. "packed" internal form.
  984.  
  985. Examples:
  986.  
  987.         "Now is the time"       /*a simple example      */
  988.  
  989.         ""                      /*a null string         */
  990.  
  991.         'Can't you see??'       /*Can't you see??       */
  992.  
  993.         '4A 3B CO'X             /*a hex string          */
  994.  
  995.         '00110111'b             /*binary for '7'        */
  996.  
  997.  
  998.  
  999. OPERATORS
  1000.  
  1001.  
  1002.  
  1003. The characters  +-*/=><*| may be combined in the sequences shown in Table 3.1
  1004.  
  1005. to form operator tokens. Operator sequences may include leading,trailing,and
  1006.  
  1007. embedded blanks,all of which are removed when the program is scanned. In
  1008.  
  1009. addition to the above characters,the blank character as a concatenation
  1010.  
  1011. operator if it follows a symbol or string and is not adjacent to an operator or
  1012.  
  1013. special character.
  1014.  
  1015.  
  1016.  
  1017. Each operator has an associated priority that determines the order in which
  1018.  
  1019. operations will be performed in an expression. Operators with higher priorities
  1020.  
  1021. before those with lower priorities.
  1022.  
  1023.  
  1024.  
  1025.                                 12
  1026.  
  1027.  
  1028.  
  1029.                          OPERATOR SEQUENCES
  1030.  
  1031.  
  1032.  
  1033. SEQUENCE                PRIORITY                OPERATOR DEFINITION
  1034.  
  1035.  
  1036.  
  1037.                         8                       Logical NOT
  1038.  
  1039. +                       8                       Prefix Conversion
  1040.  
  1041. -                       8                       Prefix Negation
  1042.  
  1043. **                      7                       Exponentiation
  1044.  
  1045. *                       6                       Multiplication
  1046.  
  1047. /                       6                       Division
  1048.  
  1049. %                       6                       Integer Division
  1050.  
  1051. //                      6                       Remainder
  1052.  
  1053. +                       5                       Addition
  1054.  
  1055. -                       5                       Subtration
  1056.  
  1057. ||                      4                       Concatenation
  1058.  
  1059. (blank)                 4                       Blank Concatenation
  1060.  
  1061. ==                      3                       Exact Equality
  1062.  
  1063. ~==                     3                       Exact Inequality
  1064.  
  1065. =                       3                       Equality
  1066.  
  1067. ~=                      3                       Inequality
  1068.  
  1069. >                       3                       Greater Than
  1070.  
  1071. >=,~<                   3                       Greater Than or Equal To
  1072.  
  1073. <                       3                       Less Than
  1074.  
  1075. <=,~>                   3                       Less Than or Equal To
  1076.  
  1077. &                       2                       Logical AND
  1078.  
  1079. |                       1                       Logical Inclusive OR
  1080.  
  1081. ^,&&                    1                       Logical Exclusive OR
  1082.  
  1083.  
  1084.  
  1085. SPECIAL CHARACTER TOKENS
  1086.  
  1087.  
  1088.  
  1089. The characters :():,are each treated as a separate special character token and
  1090.  
  1091. have particular meanings within an ARexx program. Blanks adjacent to these
  1092.  
  1093. special characters are removed,except for those preceding an open parenthesis
  1094.  
  1095. or following a close parenthesis.
  1096.  
  1097.  
  1098.  
  1099. COLON (:). A colon,if preceded by a symbol token,defines a label within the
  1100.  
  1101. program. Lavels are locations in the program to which control may be
  1102.  
  1103. transferred under various conditions.
  1104.  
  1105.  
  1106.  
  1107. OPENING AND CLOSING PARENTHESES (()). Parentheses are used in expressions to
  1108.  
  1109. group operators and operands into subexpressions,in order to override the
  1110.  
  1111. normal operator primorities. An open parenthesis also serves to identify a
  1112.  
  1113. function call within an expression;a symbol or string followed immediately by
  1114.  
  1115. an open parenthesis defines a function name. Parentheses must always be
  1116.  
  1117. balanced within a statement.
  1118.  
  1119.  
  1120.  
  1121. SEMICOLON (;). The semicolon acts as a program statement terminator. Several
  1122.  
  1123. statements may be placed on a single source line if separated by semicolons.
  1124.  
  1125.  
  1126.  
  1127.                                 13
  1128.  
  1129.  
  1130.  
  1131. COMMA (,). A comma token acs as the continuation character for statements that
  1132.  
  1133. must be entered on several source lines. It is also used to separate the
  1134.  
  1135. argument expressions in a function call.
  1136.  
  1137.  
  1138.  
  1139. CLAUSES
  1140.  
  1141.  
  1142.  
  1143. Tokens are grouped together to form clauses,the smallest language unit that can
  1144.  
  1145. be executed as a statement. Every clause in ARexx can be classified as either a
  1146.  
  1147. null,label,assignment,instruction,or command clause. The classification process
  1148.  
  1149. is very simple,since no more than two tokens are required to classify any
  1150.  
  1151. clause. Assignment,instruction,and command clauses are jointly termed
  1152.  
  1153. statements.
  1154.  
  1155.  
  1156.  
  1157. CLAUSE CONTINUATION. The end of a source line normally acts as the implicit end
  1158.  
  1159. of a clause. A clause can be continued on the next source line by ending the
  1160.  
  1161. line with a comma (,). The commas is then removed,and the next line is
  1162.  
  1163. considered as a continuation of the clause. There is no limit to the number of
  1164.  
  1165. continuations that may occur. String and comment tokens are automatically
  1166.  
  1167. continued if a line end before the closing delimiter has been found,and the
  1168.  
  1169. "newline" character is not considered to be part of the token.
  1170.  
  1171.  
  1172.  
  1173. MULTIPLE CLAUSES. Several clauses can be placed on a single line by separating
  1174.  
  1175. them with semicolons(;).
  1176.  
  1177.  
  1178.  
  1179. NULL CLAUSES
  1180.  
  1181.  
  1182.  
  1183. Lines consisting only of blanks or comments are called null clauses. They have
  1184.  
  1185. no function in the execution of a program,except to aid its readability and to
  1186.  
  1187. increment the source line count. Null clauses may appear anywhere in a program.
  1188.  
  1189. Example:
  1190.  
  1191.  
  1192.  
  1193.         /* perform annuity calculations         */
  1194.  
  1195.  
  1196.  
  1197. LABEL CLAUSES
  1198.  
  1199.  
  1200.  
  1201. A symbol followed immediately by a colon defines a label clause. A label acts
  1202.  
  1203. as a placemarker in the program,but no action occurs with the "execution" of a
  1204.  
  1205. label. The colon is considered as an implicit clause terminator,so each label
  1206.  
  1207. stands as a separate clause. Label clauses may appear anywhere in a program.
  1208.  
  1209. Examples:
  1210.  
  1211.  
  1212.  
  1213.         start:          /* begin execution      */
  1214.  
  1215.         syntax:         /* error processing     */
  1216.  
  1217.  
  1218.  
  1219. ASSIGNMENT CLAUSES
  1220.  
  1221.  
  1222.  
  1223. Assignments are identified by a variable symbol followed by an "=" operator. In
  1224.  
  1225. this context the operator's normal definition(an equality comparison)is
  1226.  
  1227. overridden,and it becomes an assignment operator. The tokens to the right of
  1228.  
  1229. the "=" are evaluated as an expression,and the result is assigned to(becomes
  1230.  
  1231. the value of)the variable symbol.
  1232.  
  1233.  
  1234.  
  1235.                                 14
  1236.  
  1237.  
  1238.  
  1239. Examples:
  1240.  
  1241.  
  1242.  
  1243.         when= 'Now is the time'
  1244.  
  1245.         answ= 3.14 * fact(5)
  1246.  
  1247.  
  1248.  
  1249. INSTRUCTION CLAUSES
  1250.  
  1251.  
  1252.  
  1253. Instructions begin with certain keyword symbols,each of which denotes a
  1254.  
  1255. particular action to be performed. Instruction keywords are recognized as such
  1256.  
  1257. only at the beginning of a clause,and may otherwise be used freely as symbols
  1258.  
  1259. (although such use may become confusing at times.) The ARexx instructions are
  1260.  
  1261. described in detail in Chapter 4.
  1262.  
  1263. Examples:
  1264.  
  1265.  
  1266.  
  1267.         drop a b c              /* reset variables      */
  1268.  
  1269.         say 'please'            /* a polite program     */
  1270.  
  1271.         if j > 5 then leave;    /* several instructions */
  1272.  
  1273.  
  1274.  
  1275. COMMAND CLAUSES
  1276.  
  1277.  
  1278.  
  1279. Commands are any ARexx expression that can't be classified as one of the
  1280.  
  1281. preceding types of clauses. The expression is evaluated and the result is
  1282.  
  1283. issued as a command to an external host,which might be the native operating
  1284.  
  1285. system or an application program. Commands are discussed in Chapter 5,and the
  1286.  
  1287. details of the host command interface are given in Chapter 10.
  1288.  
  1289. Examples:
  1290.  
  1291.  
  1292.  
  1293.         'delete' 'myfile'       /* a DOS command        */
  1294.  
  1295.         'jump' current+10       /* an editor command?   */
  1296.  
  1297.  
  1298.  
  1299. CLAUSE CLASSIFICATION
  1300.  
  1301.  
  1302.  
  1303. The process by which program lines are divided into clauses and then classified
  1304.  
  1305. is important in understanding the operation of an ARexx program. The language
  1306.  
  1307. interpreter splits the program source into groups of clauses as the program is
  1308.  
  1309. read,using the end of each line as a clause separator and applying the
  1310.  
  1311. continuation rule as required. These groups of one or more clauses are then
  1312.  
  1313. tokenized,and each clause is classified into one of the above types. Note that
  1314.  
  1315. seemingly small syntactic differences may completely change the semantic
  1316.  
  1317. content of a statement. For example,
  1318.  
  1319.  
  1320.  
  1321.         SAY 'Hello, Bill'
  1322.  
  1323.  
  1324.  
  1325. is an instruction clause and will display "Hello, Bill" on the console,but
  1326.  
  1327.  
  1328.  
  1329.         ""SAY 'Hello, Bill'
  1330.  
  1331.  
  1332.  
  1333. is a command clause,and will issue "SAY Hello, Bill" as a command to an
  1334.  
  1335. external program. The presence of the leading null string changes the
  1336.  
  1337. classification from an instruction clause to a command clause.
  1338.  
  1339.  
  1340.  
  1341.                                 15
  1342.  
  1343.  
  1344.  
  1345. EXPRESSIONS
  1346.  
  1347.  
  1348.  
  1349. Expression evaluation is an important part of ARexx programs,since most
  1350.  
  1351. statements include at least one expression. Expressions are composed of
  1352.  
  1353. strings,symbols,operators,and parentheses. Strings are used as literals in an
  1354.  
  1355. expression;their value in an operation is just the string itself. Fixed symbols
  1356.  
  1357. are also literals(remember that symbols are always translated to uppercase,)
  1358.  
  1359. but variable symbols may have an assigned value. Operator tokens represent the
  1360.  
  1361. predefined operations of ARexx;each operator has an associated priority that
  1362.  
  1363. determines the order in which operations will be performed. Parentheses may be
  1364.  
  1365. used to alter the normal order of evaluation in the expression,or to identify
  1366.  
  1367. function calls. A symbol or string followed immediately by an open parenthesis
  1368.  
  1369. defines the function name,and the tokens between the opening and(final)closing
  1370.  
  1371. parenthesis form the argument list for the function.
  1372.  
  1373.  
  1374.  
  1375. For example,the expression "J 'fractorial is' fact(J)" is composed of a symbol
  1376.  
  1377. J,a blank operator,the string 'factorial is',another blank,the symbol fact,an
  1378.  
  1379. open parenthesis,the symbol J again,and a closing parenthesis. FACT is a
  1380.  
  1381. function name and (J) is its argument list,in this case the single expression
  1382.  
  1383. J.
  1384.  
  1385.  
  1386.  
  1387. SYMBOL RESOLUTION
  1388.  
  1389.  
  1390.  
  1391. Before the evaluation of an expression can proceed,the interpreter must obtain
  1392.  
  1393. a value for each symbol in the expression. For fixed symbols the value is just
  1394.  
  1395. the symbol name itself,but variable symbols must be looked up in the current
  1396.  
  1397. symbol table. In the example above,the expression after symbol resolution would
  1398.  
  1399. be "3 'factorial is' FACT(3)," assuming that the symbol J had the value 3.
  1400.  
  1401.  
  1402.  
  1403. Suppose that the example above had been "FACT(J) 'is' J 'factorial'." Would the
  1404.  
  1405. second occurrence of symbol J still resolve to 3 in this case? In general,
  1406.  
  1407. function calls may have "side effects" that include altering the values of
  1408.  
  1409. variables,so the value of J might have been changed by the call to FACT. In
  1410.  
  1411. order to avoid ambiguities in the values assigned to symbols during the
  1412.  
  1413. resolution process, ARexx guarantees a strict left-to-right resolution order.
  1414.  
  1415. Symbol resolution proceeds irrespective of operator priority or parenthetical
  1416.  
  1417. grouping;if a function call is found,the resolution is suspended while the
  1418.  
  1419. function is evaluated. Note that it is possible for the same symbol to have
  1420.  
  1421. more than one value in an expression.
  1422.  
  1423.  
  1424.  
  1425. ORDER OF EVALUATION
  1426.  
  1427.  
  1428.  
  1429. After all symbol values have been resolved,the expression is evaluated based on
  1430.  
  1431. operator priority and subexpression grouping. Operators of higher priority are
  1432.  
  1433. evaluated first. ARexx does not guarantee an order of evaluation among
  1434.  
  1435. operators of equal priority,and does not employ a "fast path" evaluation of
  1436.  
  1437. boolean operators. For example,in the expression
  1438.  
  1439.  
  1440.  
  1441.         (1 = 2) & (FACT(3) = 6)
  1442.  
  1443.  
  1444.  
  1445. the call to the FACT function will be made,although it is clear that the final
  1446.  
  1447. result will be 0,since the first term of the AND operation is 0.
  1448.  
  1449.  
  1450.  
  1451.                                 16
  1452.  
  1453.  
  1454.  
  1455. NUMBERS AND NUMERIC PRECISION
  1456.  
  1457.  
  1458.  
  1459. An important class of operands are those representing numbers. Numbers consist
  1460.  
  1461. of the characters 0-9,.+-,and blanks;an e or E may follow a number to indicate
  1462.  
  1463. exponential notation,in which case it must be followed by a (signed) integer).
  1464.  
  1465.  
  1466.  
  1467. Both string tokens and symbol tokens may be used to specify numbers. Since the
  1468.  
  1469. language is typeless,variables do not have to be declared as "numeric" before
  1470.  
  1471. being used in an arithmetic operation. Instead,each value string is examined
  1472.  
  1473. when it is used to verify that it represents a number. The following examples
  1474.  
  1475. are all valid numbers:
  1476.  
  1477.  
  1478.  
  1479.         33
  1480.  
  1481.         "   12.3   "
  1482.  
  1483.         0.321e12
  1484.  
  1485.         ' + 15.'
  1486.  
  1487.  
  1488.  
  1489. Note that leading and trailing blanks are permitted,and that blanks may be
  1490.  
  1491. embedded between a "+" or "-" sign and the number body(but not within the
  1492.  
  1493. body.)
  1494.  
  1495.  
  1496.  
  1497. BOOLEAN VALUES
  1498.  
  1499.  
  1500.  
  1501. The numbers 0 and 1 are used to represent the boolean values False and True,
  1502.  
  1503. respectively. The use of a value other than 0 or 1 when a boolean operand is
  1504.  
  1505. expected will generate an error. Any number equivalent to 0 or 1,for example
  1506.  
  1507. "0.000" or "0.1E1," is also acceptable as a boolean value.
  1508.  
  1509.  
  1510.  
  1511. NUMERIC PRECISION
  1512.  
  1513.  
  1514.  
  1515. ARexx allows the basic precision used for arithmetic calculations to be
  1516.  
  1517. modified while a program is executing. The number of significant figures used
  1518.  
  1519. in arithmetic operations is determined by the Numeric Digits environment
  1520.  
  1521. variable, and may be modified using the NUMERIC instruction.
  1522.  
  1523.  
  1524.  
  1525. The number of decimal places used for a result depends on the operation
  1526.  
  1527. performed and the number of decimal places in the operands. Unlike many
  1528.  
  1529. languages,ARexx preserves trailing zeroes to indicate the precision of the
  1530.  
  1531. result. If the total number of digits required to express a value exceeds the
  1532.  
  1533. current Numeric Digits setting,the number is formatted in exponential notation.
  1534.  
  1535. Two such formats are provided:
  1536.  
  1537.  
  1538.  
  1539. In SCIENTIFIC notation,the exponent is adjusted so that a single digit is
  1540.  
  1541. placed to the left of the decimal point.
  1542.  
  1543.  
  1544.  
  1545. in ENGINEERING notation,the number is scaled so that the exponent is a multiple
  1546.  
  1547. of 3 and the digits to the left of the decimal point range from 1 to 999.
  1548.  
  1549.  
  1550.  
  1551. The numeric precision and format can be set using the NUMERIC instruction.
  1552.  
  1553.  
  1554.  
  1555.                                 17
  1556.  
  1557.  
  1558.  
  1559. OPERATORS
  1560.  
  1561.  
  1562.  
  1563. Operators can be grouped into four categories:
  1564.  
  1565.  
  1566.  
  1567. Arithmetic operators require one or two numeric operands,and produce a numeric
  1568.  
  1569. result.
  1570.  
  1571. Concatenation operators join two strings into a single string.
  1572.  
  1573. Comparison operators require two operands,and produce a boolean(0 or 1) result.
  1574.  
  1575. Logical Operators require one or two boolean operands,and produce a boolean
  1576.  
  1577. result.
  1578.  
  1579.  
  1580.  
  1581. ARITHMETIC OPERATORS
  1582.  
  1583.  
  1584.  
  1585. The aritmetic operators are listed in Table 3.2 below. Note the inclusion of
  1586.  
  1587. the integer division(%)and remainder(//)operators,along with the usual
  1588.  
  1589. arithmetic operations. The result of an arithmetic operation is always foratted
  1590.  
  1591. based on the current Numeric Digits setting,and will never have leading or
  1592.  
  1593. trailing blanks.
  1594.  
  1595.  
  1596.  
  1597.                          ARITHMETIC OPERATORS
  1598.  
  1599.         SEQUENCE                PRIORITY                OPERATION
  1600.  
  1601.         +                       8                       Prefix Conversion
  1602.  
  1603.         -                       8                       Prefix Negation
  1604.  
  1605.         **                      7                       Exponentiation
  1606.  
  1607.         *                       6                       Multiplication
  1608.  
  1609.         /                       6                       Division
  1610.  
  1611.         %                       6                       Integer Division
  1612.  
  1613.         //                      6                       Remainder
  1614.  
  1615.         +                       5                       Addition
  1616.  
  1617.         -                       5                       Subtraction
  1618.  
  1619.  
  1620.  
  1621. PREFIX CONVERSION(+). This unary operator converts the operand to and internal
  1622.  
  1623. numeric form and formats the result based on the current Numeric Digits
  1624.  
  1625. settings. This causes any leading and trailing blanks to be removed,and may
  1626.  
  1627. result in a loss of precision.
  1628.  
  1629. Examples:
  1630.  
  1631.  
  1632.  
  1633.         '  3.12 '               ==> 3.12
  1634.  
  1635.         1.5001                  ==> 1.500 /* If digits = 3  */
  1636.  
  1637.  
  1638.  
  1639. PREFIX NEGATION(-). This unary operator negates the operand. The result is
  1640.  
  1641. formatted based on the current Numeric Digits setting.
  1642.  
  1643.  
  1644.  
  1645.                                 18
  1646.  
  1647.  
  1648.  
  1649. Examples:
  1650.  
  1651.  
  1652.  
  1653.         -'  3.12 '              ==> -3.12
  1654.  
  1655.         1.5E2                   ==>-150
  1656.  
  1657.  
  1658.  
  1659. EXPONENTIATION(**). The left operand is raised to the power specified by the
  1660.  
  1661. right operand,which must be an integer. The number of decimal places for the
  1662.  
  1663. result is the product of the exponent and the number of decimal places in the
  1664.  
  1665. base.
  1666.  
  1667. Examples:
  1668.  
  1669.  
  1670.  
  1671.         2**3                    ==>8
  1672.  
  1673.         3**-1                   ==>.333333333
  1674.  
  1675.         0.5**3                  ==>0.125
  1676.  
  1677.  
  1678.  
  1679. MULTIPLICATION(*). The product of two numbers is computed. The number of
  1680.  
  1681. decimal places for the result is the sum of the decimal places of the operands.
  1682.  
  1683. Examples:
  1684.  
  1685.  
  1686.  
  1687.         12 * 3                  ==>36
  1688.  
  1689.         1.5 * 1.50              ==>2.250
  1690.  
  1691.  
  1692.  
  1693. DIVISION(/). The quotient of two numbers is computed. The number of decimal
  1694.  
  1695. places for the result depends on the current setting of the numeric DIGITS
  1696.  
  1697. variable;the nuber is formatted to the maximum precision required.
  1698.  
  1699. Examples:
  1700.  
  1701.  
  1702.  
  1703.         6 / 3                   ==>2
  1704.  
  1705.         8 / 3                   ==>2.66666667
  1706.  
  1707.  
  1708.  
  1709. INTEGER DIVISION(%). The quotient of two numbers is computed,and the integer
  1710.  
  1711. part of the quotient is used as the result.
  1712.  
  1713. Examples:
  1714.  
  1715.  
  1716.  
  1717.         5 % 3                   ==>1
  1718.  
  1719.         -8 % 3                  ==>-2
  1720.  
  1721.  
  1722.  
  1723. REMAINDER(//). The result is the remainder after the two operands are divided.
  1724.  
  1725. The remainder for "a//b" is calculated as "a-(a%b)*b." If both operands are
  1726.  
  1727. positive integers,this operation yields the usual "modulo" result.
  1728.  
  1729.  
  1730.  
  1731.                                 19
  1732.  
  1733.  
  1734.  
  1735. Examples:
  1736.  
  1737.  
  1738.  
  1739.         5 // 3                  ==>2
  1740.  
  1741.         -5 // 3                 ==>-2
  1742.  
  1743.         5.1 // 0.2              ==>0.1
  1744.  
  1745.  
  1746.  
  1747. ADDITION(+). The sum of two numbers is computed. The number of decimal places
  1748.  
  1749. for the result is the larger of the decimal places of the operands.
  1750.  
  1751. Examples:
  1752.  
  1753.  
  1754.  
  1755.         12 + 3                  ==>15
  1756.  
  1757.         3.1 + 4.05              ==>7.15
  1758.  
  1759.  
  1760.  
  1761. SUBTRATION(-). The difference of two numbers is computed. As in the case of
  1762.  
  1763. addition,the number of decimals places for the result is the larger of the
  1764.  
  1765. decimal places of the operands.
  1766.  
  1767. Examples:
  1768.  
  1769.  
  1770.  
  1771.         12 - 3                  ==>9
  1772.  
  1773.         5.55 - 1.55             ==>4.00
  1774.  
  1775.  
  1776.  
  1777. CONCATENATION OPERATORS
  1778.  
  1779.  
  1780.  
  1781. ARexx defines two concatenation operators,both of which require two operands.
  1782.  
  1783. The first,identified by the operator sequence "||",joins two strings into a
  1784.  
  1785. single string with no intervening blank. The second concatenation operation is
  1786.  
  1787. identified by the blank operator,and joins the two operand strings with one
  1788.  
  1789. intervening blank.
  1790.  
  1791.  
  1792.  
  1793. An implicit concatenation operator is recognized when a symbol and a string are
  1794.  
  1795. directly abutted in an expression. Concatenation by abuttal uses the "||"
  1796.  
  1797. operator,and behaves exactly as though the operator had been provided
  1798.  
  1799. explicitly.
  1800.  
  1801. Examples:
  1802.  
  1803.  
  1804.  
  1805.         'why me,' || 'Mom?'             ==>why me,Mom?
  1806.  
  1807.         'good' 'times'                  ==>good times
  1808.  
  1809.         one'two'three                   ==>ONEtwoTHREE
  1810.  
  1811.  
  1812.  
  1813. COMPARISON OPERATORS
  1814.  
  1815.  
  1816.  
  1817. Comparisons are performed in one of three modes,and always result in a boolean
  1818.  
  1819. value(0 or 1.)
  1820.  
  1821.  
  1822.  
  1823. Exact comparisons proceed character-by-character,including any leading blanks
  1824.  
  1825. that may be present.
  1826.  
  1827. String comparisons ignore leading blanks,and pad the shorter string with blanks
  1828.  
  1829. if necessary.
  1830.  
  1831.  
  1832.  
  1833.                                 20
  1834.  
  1835.  
  1836.  
  1837. Numeric comparisons first convert the operands to an internal numeric form
  1838.  
  1839. using the current Numeric Digits setting,and then perform a standard arithmetic
  1840.  
  1841. comparison.
  1842.  
  1843.  
  1844.  
  1845. Except for the exact equality and exact inequality operators,all comparison
  1846.  
  1847. operators dynamically determine whether a string of numeric comparison is to be
  1848.  
  1849. performed. A numeric comparison is performed if both operands are valid numbers
  1850.  
  1851. otherwise,the operands are compared as strings.
  1852.  
  1853.  
  1854.  
  1855.                          COMPARISON OPERATORS
  1856.  
  1857.  
  1858.  
  1859. SEQUENCE        PRIORITY        OPERATION               MODE
  1860.  
  1861.  
  1862.  
  1863. ==              3               Exact Equality          Exact
  1864.  
  1865. ~==             3               Exact Inequality        Exact
  1866.  
  1867. =               3               Equality                String/Numeric
  1868.  
  1869. ~=              3               Inequality              String/Numeric
  1870.  
  1871. >               3               Greater Than            String/Numeric
  1872.  
  1873. >=,~<           3               Greater Than or Equal   String/Numeric
  1874.  
  1875. <               3               Less Than               String/Numeric
  1876.  
  1877. <=,~>           3               Less Than or Equal      String/Numeric
  1878.  
  1879.  
  1880.  
  1881. LOGICAL (BOOLEAN) OPERATORS
  1882.  
  1883.  
  1884.  
  1885. ARexx defines the four logical operations NOT,AND,OR,and Exclusive OR,all of
  1886.  
  1887. which require boolean operands and produce a boolean result. Boolean operands
  1888.  
  1889. must have values of either 0(False)or 1(True.) An attempt to perform a logical
  1890.  
  1891. operation on a non-boolean operand will generate an error.
  1892.  
  1893.  
  1894.  
  1895.                          LOGICAL OPERATORS
  1896.  
  1897.  
  1898.  
  1899.         SEQUENCE        PRIORITY        OPERATION
  1900.  
  1901.  
  1902.  
  1903.         ~               8               NOT(Inversion)
  1904.  
  1905.         &               2               AND
  1906.  
  1907.         |               1               OR
  1908.  
  1909.         ^,&&            1               Exclusive OR
  1910.  
  1911.  
  1912.  
  1913. STEMS AND COMPOUND SYMBOLS
  1914.  
  1915.  
  1916.  
  1917. Stems and compound symbols have special properties that allow for some
  1918.  
  1919. interesting and unusual programming. A compound symbol can be regarded as
  1920.  
  1921. having the structure stem.n1.n2.n3...nk where the leading name is a stem symbol
  1922.  
  1923. and each node n1...nk is a fixed or simple symbol. Whenever a compound symbol
  1924.  
  1925. appears in a program,its name is expanded by replacing each node with its
  1926.  
  1927. current value as a (simple) symbol. The value string may consist of any
  1928.  
  1929. characters,including embedded blanks,and is not converted to uppercase. The
  1930.  
  1931. result of the expansion is a new name that is used in place of the compound
  1932.  
  1933. symbol. For example if j has the value of 3 and k has the value 7,then the
  1934.  
  1935. compound symbol a.j.k will expand to A.3.7.
  1936.  
  1937.  
  1938.  
  1939. Stem symbols provide a way to initialize a whole class of compound symbols.
  1940.  
  1941. When an assignment is made to a stem symbol,it assigns that value to all
  1942.  
  1943. possible compound symbols derived from the stem. Thus,the value of a compound
  1944.  
  1945. symbol depends on the prior assignments made to itself or its associated stem.
  1946.  
  1947.  
  1948.  
  1949.                                 21
  1950.  
  1951.  
  1952.  
  1953. Compound symbols can be regarded as a form of "associative" or "content-
  1954.  
  1955. addressable" memory. For example,suppose that you needed to store and retrieve
  1956.  
  1957. a set of names and telephone numbers. The conventional approach would be to set
  1958.  
  1959. up two arrays NAME and NUMBER,each indexed by an integer running from one to
  1960.  
  1961. the number of entries. A number would be "looked up" by scanning the name array
  1962.  
  1963. until the given name was found,say in NAME.12,and then retrieving NUMBER.12.
  1964.  
  1965. With compound symbols,the symbol NAME could hold the name to be looked-up,and
  1966.  
  1967. NUMBER.NAME would then expand to NUMBER.Bill(for example),which be the
  1968.  
  1969. corresponding number.
  1970.  
  1971.  
  1972.  
  1973. Of course,compound symbols can also be used as conventional indexed arrays,with
  1974.  
  1975. the added convenience that only a single assignment(to the stem)is required to
  1976.  
  1977. initialize the entire array.
  1978.  
  1979.  
  1980.  
  1981. THE EXECUTION ENVIRONMENT
  1982.  
  1983.  
  1984.  
  1985. The ARexx interpreter provides a uniform environment by running each program as
  1986.  
  1987. a separate task(actually,as a DOS process)in the Amiga's multitasking operating
  1988.  
  1989. system. This allows for a flexible interface between an external host program
  1990.  
  1991. and the interpreter,as the host can either proceed concurrently with its
  1992.  
  1993. operations or can simply wait for the interpreted program to finish.
  1994.  
  1995.  
  1996.  
  1997. THE EXTERNAL ENVIRONMENT
  1998.  
  1999.  
  2000.  
  2001. The external environment of a program includes its task(process)structure,
  2002.  
  2003. input and output streams,and current directory. When each ARexx task is
  2004.  
  2005. created,it inherits the input and output streams and current directory from its
  2006.  
  2007. client,the external program that invoked the ARexx program. The current
  2008.  
  2009. directory is used as the starting point in a search for a program or data file.
  2010.  
  2011.  
  2012.  
  2013. EXTERNAL PROGRAMS. The external environment usually includes one or more
  2014.  
  2015. external programs with which the ARexx program may communicate. Any program
  2016.  
  2017. that supports a suitable interface can receive commands from ARexx programs.
  2018.  
  2019. The command interface is discussed in Chapter 5.
  2020.  
  2021.  
  2022.  
  2023. THE INTERNAL ENVIRONMENT
  2024.  
  2025.  
  2026.  
  2027. The internal environment of an ARexx program consists of a static global
  2028.  
  2029. structure and one or more storage environments. The global data values are
  2030.  
  2031. fixed at a time the program is invoked,and include the argument strings,program
  2032.  
  2033. source code,and static data strings. The storage environment includes the
  2034.  
  2035. symbol table used for variable values,the numeric options,trace options,and
  2036.  
  2037. host address strings. While the global environment is unique,there may be many
  2038.  
  2039. storage environments during the course of the program execution. Each time an
  2040.  
  2041. internal function is called a new storage environment is activated and
  2042.  
  2043. initialized. The initial values for most fields are inherited from the previous
  2044.  
  2045. environment,but values may be changed afterwards without affecting the caller's
  2046.  
  2047. environment. The new environment persists until control returns from the
  2048.  
  2049. function.
  2050.  
  2051.  
  2052.  
  2053.                                 22
  2054.  
  2055.  
  2056.  
  2057. ARGUMENT STRINGS. A program may receive one or more argument strings when it is
  2058.  
  2059. first invoked. These arguments persist for the duration of the program and are
  2060.  
  2061. never altered. The number of arguments a program receives depends in part on
  2062.  
  2063. the mode of invocation. ARexx programs invoked as commands normally have only
  2064.  
  2065. one argument string,although the "command tokenization" option may provide more
  2066.  
  2067. than one. A program invoked as a function can have any number of arguments if
  2068.  
  2069. called as an internal function,but external functions are limited to a maximum
  2070.  
  2071. of 15 arguments.
  2072.  
  2073.  
  2074.  
  2075. The argument strings can be retrieved using either the ARG instruction or the
  2076.  
  2077. ARG() Built-In function. ARG() can also return the total number of arguments,or
  2078.  
  2079. the status(as "exists" or "omitted")of a particular argument.
  2080.  
  2081.  
  2082.  
  2083. THE SYMBOL TABLE. Every storage environment includes a symbol table to store
  2084.  
  2085. the value strings that have been assigned to variables. This symbol table is
  2086.  
  2087. organized as a two-level stores entries for simple and stem symbols,and the
  2088.  
  2089. secondary level is used for compound symbols. All of the compound symbols
  2090.  
  2091. associated with a particular stem are stored in one tree,with the root of the
  2092.  
  2093. tree held by the entry for the stem.
  2094.  
  2095.  
  2096.  
  2097. Symbols are not entered into the table until an assignment is made to the
  2098.  
  2099. symbol. Once created,entries at the primary level are never removed,even if the
  2100.  
  2101. symbol subsequently becomes uninitialized. Secondary trees are released
  2102.  
  2103. whenever an assignment is made to the stem associated with the tree.
  2104.  
  2105.  
  2106.  
  2107.  
  2108.  
  2109. INPUT AND OUTPUT
  2110.  
  2111.  
  2112.  
  2113. Most computer programs require some means of communicating with the outside
  2114.  
  2115. world,either to accept input data or to pass along results. The REXX language
  2116.  
  2117. includes only a minimal specification of input and output (I/O)operations,
  2118.  
  2119. leaving the choice of additional functionality to the language implementor.
  2120.  
  2121. This is in keeping with the design of many computer languages. For instance,the
  2122.  
  2123. "C" language has no statements dedicated to I/O,but instead relies on a
  2124.  
  2125. standardized set of I/O functions.
  2126.  
  2127.  
  2128.  
  2129. ARexx extends the I/O facilities fo REXX by providing Built-In functions to
  2130.  
  2131. manipulate external files. Files are referenced by a logical name associated
  2132.  
  2133. with the file when it is first opened. The initial input and output streams are
  2134.  
  2135. given the names STDIN and STDOUT.
  2136.  
  2137.  
  2138.  
  2139. ARexx maintains a list of all of the files opened by a program and
  2140.  
  2141. automatically closes them when the program finishes. There is no limit to the
  2142.  
  2143. number of files that may be open simultaneously.
  2144.  
  2145.  
  2146.  
  2147.                                 23
  2148.  
  2149.  
  2150.  
  2151. RESOURCE TRACKING
  2152.  
  2153.  
  2154.  
  2155. ARexx provides complete tracking for all of the dynamically-allocated resources
  2156.  
  2157. that it uses to execute a program. These resources include memory space,DOS
  2158.  
  2159. files and related structures,and the message port structures supported by
  2160.  
  2161. ARexx. The tracking system was designed to allow a program to "bail out" at any
  2162.  
  2163. point(perhaps due to an execution error)without leaving any hanging resources.
  2164.  
  2165.  
  2166.  
  2167. It is possible to go outside of the interpreter's resource tracking net by
  2168.  
  2169. making calls directly to the Amiga's operating system from within an ARexx
  2170.  
  2171. program. In these cases it is the programer's responsibility to track and
  2172.  
  2173. return all of the allocated resources. ARexx provides a special interrupt
  2174.  
  2175. facility so that a program can retain control after an execution error,perform
  2176.  
  2177. the required cleanup,and then make an orderly exit. Chapter 7 has information
  2178.  
  2179. on the ARexx interrupt system.
  2180.  
  2181.  
  2182.  
  2183.                                 24
  2184.  
  2185.  
  2186.  
  2187.                            INSTRUCTIONS
  2188.  
  2189.  
  2190.  
  2191. Instruction clauses are identified by an initial keyword symbol that is not
  2192.  
  2193. followed by a colon(:)or an equals(=)operator. Each instruction signifies a
  2194.  
  2195. specific action,and may be followed by one or more subkeywords,expressions,or
  2196.  
  2197. other instruction-specific information. Instruction keywords and subkeywords
  2198.  
  2199. are recognized only in this specific context,and are therefore not "reserved
  2200.  
  2201. words" in the usual sense of the term. Keywords may be used freely as variables
  2202.  
  2203. or function names,although such usage may become confusing at times.
  2204.  
  2205.  
  2206.  
  2207. In the descriptions that follow,keywords are shown in uppercase and optional
  2208.  
  2209. parts of the instruction are enclosed in brackets. Alternative selections are
  2210.  
  2211. separated by a vertical bar(|),and required alternative are enclosed in braces
  2212.  
  2213. ({}).
  2214.  
  2215.  
  2216.  
  2217. ADDRESS
  2218.  
  2219.  
  2220.  
  2221. Usage: ADDRESS [Symbol|string|VALUE] [expression]]
  2222.  
  2223. This instruction specifies a host address for commands issued by the
  2224.  
  2225. interpreter. A host address is the name associated with an external program to
  2226.  
  2227. which commands can be sent;external hosts are described in Chapter 5. ARexx
  2228.  
  2229. maintains two host addresses:a "current" and a "previous"address is lost,and
  2230.  
  2231. the "current" and a "previous" value. Whenever a new host address is supplied,
  2232.  
  2233. the "previous" address is lost,and the "current" address becomes the "previous"
  2234.  
  2235. one. These host addresses are part of a program's storage environment and are
  2236.  
  2237. preserved across internal function calls. The current address can be retrieved
  2238.  
  2239. with the Built-In function ADDRESS(). There are four distinct forms for the
  2240.  
  2241. ADDRESS instruction:
  2242.  
  2243.  
  2244.  
  2245. ADDRESS {string | symbol} expression. The expression is evaluated and the
  2246.  
  2247. result is issued to the host specified by the string or symbol,which is taken
  2248.  
  2249. as a literal. No changes are made to the current or previous address strings.
  2250.  
  2251. This provides a convenient way to issue a single command to an external host
  2252.  
  2253. without disturbing the current host addresses. The return code from the command
  2254.  
  2255. is treated as it would be from a command clause.
  2256.  
  2257.  
  2258.  
  2259. ADDRESS {string | symbol}. The string or symbol,taken as a literal,specifies
  2260.  
  2261. the new host address. The current host address becomes the previous address.
  2262.  
  2263.  
  2264.  
  2265. ADDRESS [VALUE] expression. The result of the expression specifies the new host
  2266.  
  2267. address,and the current address becomes the previous address. The VALUE keyword
  2268.  
  2269. may be omitted if the first token of the expression is not a symbol or string.
  2270.  
  2271.  
  2272.  
  2273. ADDRESS. This form interchanges the current and previous hosts. Repeated
  2274.  
  2275. execution will therefore "toggle" between the two host addresses.
  2276.  
  2277.  
  2278.  
  2279.         Examples:
  2280.  
  2281.  
  2282.  
  2283. address edit            /* set an new host address      */
  2284.  
  2285. address edit 'top'      /* move to the top              */
  2286.  
  2287. address VALUE edit n    /* compute a new host address   */
  2288.  
  2289. address                 /* swap current and previous    */
  2290.  
  2291.  
  2292.  
  2293.                                 25
  2294.  
  2295.  
  2296.  
  2297. Usage: ARG [template] [,template...]
  2298.  
  2299. ARG is shorthand form for the PARSE UPPER ARG instruction. It retrieves one or
  2300.  
  2301. more of the argument strings available to the program,and assigns values to the
  2302.  
  2303. variables in the template. The number of argument strings available depends on
  2304.  
  2305. the whether the program was invoked as a command or a function. Command
  2306.  
  2307. invocations normally have only one argument string,but functions may have up to
  2308.  
  2309. 15. The argument strings are not altered by the ARG instruction.
  2310.  
  2311.  
  2312.  
  2313. The structure and processing of templates is described briefly with the PARSE
  2314.  
  2315. instruction,and in greater depth in Chapter 8.
  2316.  
  2317.         Example:
  2318.  
  2319.  
  2320.  
  2321. arg first,second /* fetch arguments */
  2322.  
  2323.  
  2324.  
  2325. BREAK
  2326.  
  2327.  
  2328.  
  2329. Usuage: BREAK
  2330.  
  2331. The BREAK instruction is used to exit from the range of a DO instruction or
  2332.  
  2333. from within an INTERPRETed string,and is valid only in these contexts. If used
  2334.  
  2335. within a DO statement,BREAK exits from the innermost DO statement containing
  2336.  
  2337. the BREAK. This contrasts with the otherwise similar LEAVE instruction,which
  2338.  
  2339. exits only from an interative DO.
  2340.  
  2341.         Example:
  2342.  
  2343.  
  2344.  
  2345. do                      /* begin block          */
  2346.  
  2347.   if i>3 then break     /* all done?            */
  2348.  
  2349.   a = a + 1
  2350.  
  2351.   y.a = name
  2352.  
  2353.   end                   /* end block            */
  2354.  
  2355.  
  2356.  
  2357. CALL
  2358.  
  2359.  
  2360.  
  2361. Usage: CALL {symbol | string} [expression] [,expression,...]
  2362.  
  2363. The CALL instruction is used to invoke an internal or external function. The
  2364.  
  2365. function name is specified by the symbol or string token,which is taken as a
  2366.  
  2367. literal. Any expressions that follow are evaluated and become the arguments to
  2368.  
  2369. the called function. The value returned by the function is assigned to the
  2370.  
  2371. special variable RESULT. It is not an error if a result string is not returned;
  2372.  
  2373. in this case the variable RESULT is DROPed(becomes uninitialized.)
  2374.  
  2375.  
  2376.  
  2377. The linkage to the function is established dynamically at the time of the call.
  2378.  
  2379. ARexx follows a specific search order in attempting to locate the called
  2380.  
  2381. function;this process is described in Chapter 6.
  2382.  
  2383.         Example:
  2384.  
  2385.  
  2386.  
  2387. call center name,length+4,'+'
  2388.  
  2389.  
  2390.  
  2391.                                 26
  2392.  
  2393.  
  2394.  
  2395. Usage: DO [var=exp] [To exp] [BY exp]] [FOR exp] [FOREVER] [WHILE exp | UNTIL
  2396.  
  2397. exp]
  2398.  
  2399. The DO instruction begins a group of instructions to be executed as a block.
  2400.  
  2401. The range of the DO instruction includes all statements up to and including an
  2402.  
  2403. eventual END instruction. There are two basic forms of the instruction:
  2404.  
  2405.  
  2406.  
  2407. The DO keyword by itself defines a block of instructions to be executed once.
  2408.  
  2409.  
  2410.  
  2411. If any iteration specifiers follow the DO keyword,the block of instructions is
  2412.  
  2413. executed repeatedly until a termination condition occurs.
  2414.  
  2415.  
  2416.  
  2417. An interative DO instruction is sometimes called a "loop",since the interpreter
  2418.  
  2419. "loops back" to perform the instruction repeatedly. The various parts of the DO
  2420.  
  2421. instruction are described below.
  2422.  
  2423.  
  2424.  
  2425. Initializer expression. An initializer expression of the form "variable=
  2426.  
  2427. expression" defines the index variable of the loop. The expression is evaluated
  2428.  
  2429. when the DO range is first activated,and the result is assigned to the index
  2430.  
  2431. variable. On subsequent iterations an expression of the form "variable =
  2432.  
  2433. variable + increment" is evaluated,where the increment is the result of the BY
  2434.  
  2435. expression. If specified, the initializer expression must precede any of the
  2436.  
  2437. other subkeywords.
  2438.  
  2439.  
  2440.  
  2441. BY expression. The expression following a BY symbol defines the increment to be
  2442.  
  2443. added to the index variable in each subsequent iteration. The expression must
  2444.  
  2445. yield a numeric result,which may be positive or negative and need not be an
  2446.  
  2447. integer. The default increment is 1.
  2448.  
  2449.  
  2450.  
  2451. TO expression. The result of the TO expression specifies the upper(or lower)
  2452.  
  2453. limit for the index variable. At each iteration the index variable is compared
  2454.  
  2455. to the TO result. If the increment(BY result)is positive and the variable is
  2456.  
  2457. greater than the limit,the DO instruction terminates and control passes to the
  2458.  
  2459. statement following the END instruction. Similarly,the loop terminates if the
  2460.  
  2461. increment is negative and the index variable is less than the limit.
  2462.  
  2463.  
  2464.  
  2465. FOR expression. The FOR expression must yield a positive whole number when
  2466.  
  2467. evaluated,and specifies the maximum number of iterations to be performed. The
  2468.  
  2469. loop terminates when this limit is reached irrespective of the value of the
  2470.  
  2471. index variable.
  2472.  
  2473.  
  2474.  
  2475. FOREVER. The FOREVER keyword can be used if an iterative DO instruction is
  2476.  
  2477. required but no index variable is necessary. Presumably the loop will be
  2478.  
  2479. terminated by a LEAVE or BREAK instruction contained within the loop body.
  2480.  
  2481.  
  2482.  
  2483. WHILE expression. The WHILE expression is evaluated at the beginning of each
  2484.  
  2485. iteration and must result in a boolean value. The iteration proceeds if the
  2486.  
  2487. result is 1;otherwise,the loop terminates.
  2488.  
  2489.  
  2490.  
  2491.                                 27
  2492.  
  2493.  
  2494.  
  2495. UNTIL expression. The UNTIL expression is evaluated at the end of each
  2496.  
  2497. iteration and must result in a boolean value. The instruction continues with
  2498.  
  2499. the next iteration if the result is 0,and terminates otherwise.
  2500.  
  2501.  
  2502.  
  2503. The initializer,BY,TO,and FOR expressions are evaluated only when the
  2504.  
  2505. instruction is first activated,so the increment and limits are fixed throughout
  2506.  
  2507. the execution. Note that a limit need not be supplied;for example,the
  2508.  
  2509. instruction "DO i=1" will simply count away forever. Note also that only one of
  2510.  
  2511. the WHILE or UNTIL keywords can be specified.
  2512.  
  2513. Example:
  2514.  
  2515.  
  2516.  
  2517. do i=1 to limit for 5 while time <50
  2518.  
  2519.    y.1=i*time
  2520.  
  2521.    end
  2522.  
  2523.  
  2524.  
  2525. 4-6 DROP
  2526.  
  2527.  
  2528.  
  2529. Usage: DROP variable [variable...]
  2530.  
  2531. The specified variable symbols are reset to their uninitialized state,in which
  2532.  
  2533. the value of the variable is the variable name itself. It is not an error to
  2534.  
  2535. DROP a variable that is already uninitialized. DROPping a stem symbol is
  2536.  
  2537. equivalent to DROPping the values of all possible compound symbols derived from
  2538.  
  2539. that stem.
  2540.  
  2541. Example:
  2542.  
  2543.  
  2544.  
  2545. a=123           /* assign a value       */
  2546.  
  2547. drop a b        /* drop some            */
  2548.  
  2549. say a b         /* ==>A B               */
  2550.  
  2551.  
  2552.  
  2553. 4-7 ECHO
  2554.  
  2555.  
  2556.  
  2557. Usage: ECHO [expression]
  2558.  
  2559. The ECHO instruction is a synonym for the SAY instruction. It displays the
  2560.  
  2561. expression result on the console.
  2562.  
  2563. Example:
  2564.  
  2565.  
  2566.  
  2567. echo  "You don't SAY!"
  2568.  
  2569.  
  2570.  
  2571. ELSE
  2572.  
  2573.  
  2574.  
  2575. Usage: ELSE [;] [conditional statement]
  2576.  
  2577. The ELSE instruction provides the alternative conditional branch for an IF
  2578.  
  2579. statement. It is valid only within the range of an IF instruction,and must
  2580.  
  2581. follow the conditional statement of the THEN branch. If the THEN branch wasn't
  2582.  
  2583. executed,the statement following the ELSE clause is performed.
  2584.  
  2585.  
  2586.  
  2587. Binding. ELSE clauses always bind to the nearest(preceding)IF statement. It may
  2588.  
  2589. be necessary to provide "dummy" ELSE clauses for the inner IF ranges of a
  2590.  
  2591. compound IF statement in order to allow alternative branches for the outer IF
  2592.  
  2593. statements. In this case it is not sufficient to follow the else with a
  2594.  
  2595. semicolon or a null clause. Instead,the NOP(no-operation)instruction can be
  2596.  
  2597. used for this purpose.
  2598.  
  2599.  
  2600.  
  2601.                                 28
  2602.  
  2603.  
  2604.  
  2605. Example:
  2606.  
  2607.  
  2608.  
  2609. if 1 > 2 then say 'really?'
  2610.  
  2611.          else say 'I thought so'
  2612.  
  2613.  
  2614.  
  2615. END
  2616.  
  2617.  
  2618.  
  2619. Usage: END [variable]
  2620.  
  2621. The END instruction terminates the range of a DO or SELECT instruction. If the
  2622.  
  2623. optional variable symbol is supplied,it is compared to the index variable of
  2624.  
  2625. the DO statement(which must therefore be iterative). An error is generated if
  2626.  
  2627. the symbols do not match,so this provides a simple mechanism for matching the
  2628.  
  2629. DO and END statements.
  2630.  
  2631. Example:
  2632.  
  2633.  
  2634.  
  2635. do i=1 to 5             /* index variable is I  */
  2636.  
  2637.    say i
  2638.  
  2639.    end i                /* end "I" loop         */
  2640.  
  2641.  
  2642.  
  2643. EXIT
  2644.  
  2645.  
  2646.  
  2647. Usage: EXIT [expression]
  2648.  
  2649. The EXIT instruction terminates the execution of a program,and is valid
  2650.  
  2651. anywhere within a program. The evaluated expression is passed back to the
  2652.  
  2653. caller as the function or command result.
  2654.  
  2655.  
  2656.  
  2657. Results Processing. The processing of the EXIT result depends on whether a
  2658.  
  2659. result string was requested by the calling program,and whether the current
  2660.  
  2661. invocation resulted from a command or function call. If a result string was
  2662.  
  2663. requested,the expression result is copied to a block of allocated memory and a
  2664.  
  2665. pointer to the block is returned as the secondary result of the call.
  2666.  
  2667.  
  2668.  
  2669. If the caller did not request a result string,and the program was invoked as a
  2670.  
  2671. command,then an attempt is made to convert the expression result to an
  2672.  
  2673. integer. This value is then returned as the primary result,with 0 as the
  2674.  
  2675. secondary result. This allows the EXIT expression to be interpreted as a
  2676.  
  2677. "return code" by the caller. Refer to Chapter 10 for further information on
  2678.  
  2679. the data structures used to return the result string.
  2680.  
  2681. Examples:
  2682.  
  2683.  
  2684.  
  2685. exit                    /* no result needed     */
  2686.  
  2687. exit 12                 /* an error return?     */
  2688.  
  2689.  
  2690.  
  2691. IF
  2692.  
  2693.  
  2694.  
  2695. Usage: IF expression [THEN] [;] [conditional statement]
  2696.  
  2697. The IF instruction is used in conjunction with THEN and ELSE instruction to
  2698.  
  2699. conditionally execute a statement. The result of the expression must be a
  2700.  
  2701. boolean value. If the result is 1 (True),the statement following the THEN
  2702.  
  2703. symbol is executed;otherwise,control passes to the next statement(which might
  2704.  
  2705. be an ELSE clause.) The THEN keyword need not immediately follow the IF
  2706.  
  2707. expression,but may appear as a separate clause. The instruction
  2708.  
  2709.  
  2710.  
  2711.                                 29
  2712.  
  2713.  
  2714.  
  2715. is actually analyzed as "IF expression; THEN; statement;." In essence,the IF
  2716.  
  2717. statement begins a syntactic range and establishes the test condition that
  2718.  
  2719. determines whether subsequent THEN or ELSE clauses will be performed.
  2720.  
  2721.  
  2722.  
  2723. Any valid statement may follow the THEN symbol;in particular,a "DO; ... END;"
  2724.  
  2725. group allows a series of statements to be performed conditionally.
  2726.  
  2727. Examples:
  2728.  
  2729.  
  2730.  
  2731. if result < 0 then exit    /* all done?   */
  2732.  
  2733.  
  2734.  
  2735. INTERPRET
  2736.  
  2737.  
  2738.  
  2739. Usage: INTERPRET expression
  2740.  
  2741. The expression is evaluated and the result is executed as one or more program
  2742.  
  2743. statements. The statements are considered as a group,as though surrounded by a
  2744.  
  2745. "DO; ...;END" combination. Any statements can be included in the INTERPRETed
  2746.  
  2747. source,including DO or SELECT instruction.
  2748.  
  2749.  
  2750.  
  2751. An INTERPRET instruction activates a control range when it is executed,which
  2752.  
  2753. serves as a "fence" for LEAVE and ITERATE instructions. These instructions can
  2754.  
  2755. therefore be used only with DO-loops defined within the INTERPRET. The BREAK
  2756.  
  2757. instuction can be used to terminate the processing of INTERPRETed statements.
  2758.  
  2759. While it is not an error to include label clauses within the interpreted
  2760.  
  2761. string,only those labels defined in the original source code are searched
  2762.  
  2763. during a transfer of control.
  2764.  
  2765.  
  2766.  
  2767. The INTERPRET instruction can be used to solve programming problems in
  2768.  
  2769. interesting and novel ways. Programs can be constructed dynamically and then
  2770.  
  2771. executed using this instruction,or program fragments may be passed as arguments
  2772.  
  2773. to functions,which then INTERPRET them.
  2774.  
  2775. Example:
  2776.  
  2777.  
  2778.  
  2779. inst = 'say'            /* an instruction       */
  2780.  
  2781. interpret inst hello    /* ..."say HELLO"       */
  2782.  
  2783.  
  2784.  
  2785. ITERATE
  2786.  
  2787.  
  2788.  
  2789. Usage: ITERATE [variable]
  2790.  
  2791. The ITERATE instruction terminates the current iteration of a DO instruction
  2792.  
  2793. and begins the next iteration. Effectively,control passes to the END statement
  2794.  
  2795. and then(depending on the outcome of the UNTIL expression)back to the DO
  2796.  
  2797. statement. The instruction normally acts on the innermost iterative DO range
  2798.  
  2799. containing the instruction. An error results if the LEAVE instruction is not
  2800.  
  2801. contained within an iterative DO instruction.
  2802.  
  2803.  
  2804.  
  2805. The optional variable symbol specifies which DO range is to be exited,in the
  2806.  
  2807. event that several nested ranges exist. The variable is taken as a literal and
  2808.  
  2809. must match the index variable of a currently active DO instruction. An error
  2810.  
  2811. results if no such matching DO instruction is found.
  2812.  
  2813.  
  2814.  
  2815.                                 30
  2816.  
  2817.  
  2818.  
  2819. Example:
  2820.  
  2821.  
  2822.  
  2823.         do i=1 to 3
  2824.  
  2825.            if i=j then iterate i
  2826.  
  2827.            end
  2828.  
  2829.  
  2830.  
  2831. LEAVE
  2832.  
  2833.  
  2834.  
  2835. Usage:LEAVE [variable]
  2836.  
  2837. LEAVE forces an immediate exit from the iterative DO range containing the
  2838.  
  2839. instruction. An error results if the LEAVE instruction is not contained within
  2840.  
  2841. an iterative DO instruction.
  2842.  
  2843.  
  2844.  
  2845. The optional variable symbol specifies which DO range is to be exited,in the
  2846.  
  2847. event that several nested ranges exist. The variable is taken as a literal and
  2848.  
  2849. must match the index variable of a currently active DO instruction. An error
  2850.  
  2851. results if no such matching DO instruction is found.
  2852.  
  2853. Example:
  2854.  
  2855.  
  2856.  
  2857.         do i=1 to limit
  2858.  
  2859.            if i > 5 then leave  /* maximum iterations  */
  2860.  
  2861.            end
  2862.  
  2863.  
  2864.  
  2865. NOP
  2866.  
  2867.  
  2868.  
  2869. Usage: NOP
  2870.  
  2871. The NOP or "no-operation" instruction does just that:nothing. It is provided to
  2872.  
  2873. control the binding of ELSE clauses in compound IF statements.
  2874.  
  2875. Example:
  2876.  
  2877.  
  2878.  
  2879.         if i=j then             /* first (outer) IF     */
  2880.  
  2881.            if j=k then a=o      /* inner IF             */
  2882.  
  2883.                 else nop        /* binds to inner IF    */
  2884.  
  2885.            else a=a+1           /* binds to outer IF    */
  2886.  
  2887.  
  2888.  
  2889. NUMERIC
  2890.  
  2891.  
  2892.  
  2893. Usage: NUMERIC {DIGITS | FUZZ} expression
  2894.  
  2895.    or: NUMERIC FORM {SCIENTIFIC | ENGINEERING}
  2896.  
  2897. This instruction sets options relating to the numeric precision and format. The
  2898.  
  2899. valid forms of the NUMERIC instruction are:
  2900.  
  2901.  
  2902.  
  2903. NUMERIC DIGITS expression. Specifies the number of digits of precision for
  2904.  
  2905. arithmetic calculations. The expression must evaluate to a positive whole
  2906.  
  2907. number.
  2908.  
  2909.  
  2910.  
  2911. NUMERIC FUZZ expression. Specifies the number of digits to be ignored in
  2912.  
  2913. numeric comparison operations. This must be a positive whole number that is
  2914.  
  2915. less than the current DIGITS setting.
  2916.  
  2917.  
  2918.  
  2919. NUMERIC FORM SCIENTIFIC. Specifies that numbers that require exponential
  2920.  
  2921. notation be expressed in SCIENTIFIC notation. The exponent is adjusted so that
  2922.  
  2923. the mantissa (for non-zero) numbers) is between 1 and 10. This is the default
  2924.  
  2925. format.
  2926.  
  2927.  
  2928.  
  2929.                                 31
  2930.  
  2931.  
  2932.  
  2933. NUMERIC FORM ENGINEERING. Selects ENGINEERING format for numbers that require
  2934.  
  2935. exponential notation. ENGINEERING format normalizes a number so that its
  2936.  
  2937. exponent is a multiple of three and the mantissa(if not 0)is between 1 and
  2938.  
  2939. 1000.
  2940.  
  2941.  
  2942.  
  2943. The numberic options are preserved when an internal function is called.
  2944.  
  2945. Examples:
  2946.  
  2947.  
  2948.  
  2949.         numeric digits 12               /* precision            */
  2950.  
  2951.         numeric form scientific         /* format               */
  2952.  
  2953.  
  2954.  
  2955. OPTIONS
  2956.  
  2957.  
  2958.  
  2959. Usage: OPTIONS [FAILAT expression]
  2960.  
  2961.    or: OPTIONS [PROMPT expression]
  2962.  
  2963.    or: OPTIONS [RESULTS]
  2964.  
  2965. The OPTIONS instruction is used to set various internal defaults. The FAILAT
  2966.  
  2967. expression sets the limit at or above which command return codes will be
  2968.  
  2969. signalled as errors,and must evaluate to an integer value. The PROMPT
  2970.  
  2971. expression provides a string to be used as the prompt with the PULL (or PARSE
  2972.  
  2973. PULL)instruction. The RESULTS keyword indicates that the interpreter should
  2974.  
  2975. request a result string when it issues commands to an external host.
  2976.  
  2977.  
  2978.  
  2979. The internal options controlled by this instruction are preserved across
  2980.  
  2981. function calls,so an OPTIONS instruction can be issued within an internal
  2982.  
  2983. function without affecting the callers environment. If no keyword is specified
  2984.  
  2985. with the OPTIONS instuction,all controlled options revert to their default
  2986.  
  2987. settings.
  2988.  
  2989. Example:
  2990.  
  2991.  
  2992.  
  2993.         options failat 10
  2994.  
  2995.         options prompt "Yes Boss?"
  2996.  
  2997.         options results
  2998.  
  2999.  
  3000.  
  3001. OTHERWISE
  3002.  
  3003.  
  3004.  
  3005. Usage: OTHERWISE [;] [conditional statement]
  3006.  
  3007. This instruction is valid only within the range of a SELECT instruction,and
  3008.  
  3009. must follow the "WHEN ... THEN" statements. If none of the preceding WHEN
  3010.  
  3011. clauses have succeeded,the statement following the OTHERWISE instruction is
  3012.  
  3013. executed. An OTHERWISE is not mandatory within a SELECT range. However,an error
  3014.  
  3015. will result if the OTHERWISE clause is omitted and none of the WHEN
  3016.  
  3017. instructions succeed.
  3018.  
  3019. Example:
  3020.  
  3021.  
  3022.  
  3023.         select
  3024.  
  3025.                 when i=1 then say 'one'
  3026.  
  3027.                 when i=2 then say 'two'
  3028.  
  3029.                 otherwise say 'other'
  3030.  
  3031.                 end
  3032.  
  3033.  
  3034.  
  3035.                                 32
  3036.  
  3037.  
  3038.  
  3039. PARSE
  3040.  
  3041.  
  3042.  
  3043. Usage: PARSE [UPPER] inputsorce [template] [,template...]
  3044.  
  3045. The PARSE instruction provides a mechanism to extract one or more substrings
  3046.  
  3047. from a string and assign them to variables. The input string can come from a
  3048.  
  3049. variety of sources,including argument strings,an expression,or from the
  3050.  
  3051. console. The template provides both the variables to be given values and the
  3052.  
  3053. way to determine the value strings. The template may be omitted if the
  3054.  
  3055. instruction is intended only to create the input string. The different options
  3056.  
  3057. of the instruction are described below.
  3058.  
  3059.  
  3060.  
  3061. INPUT SOURCES
  3062.  
  3063.  
  3064.  
  3065. The sources for the input strings are specified by the keyword symbols listed
  3066.  
  3067. below. When multiple templates are supplied,each template receives a new input
  3068.  
  3069. string, although for some source options the new string will be identical to
  3070.  
  3071. the previous one. The input source string is copied before being parsed,so the
  3072.  
  3073. original strings are never altered by the parsing process.
  3074.  
  3075.  
  3076.  
  3077. UPPER. This optional keyword may be used with any of the input sources,and
  3078.  
  3079. specifies that the input string is to be translated to uppercase before being
  3080.  
  3081. parsed. It must be the first token following PARSE.
  3082.  
  3083.  
  3084.  
  3085. ARG. This input option retrieves the argument strings supplied when the program
  3086.  
  3087. was invoked. Command invocations normally have only a single argument string,
  3088.  
  3089. but functions may have up to 15 argument strings. Multiple templates may be
  3090.  
  3091. given to retrieve successive argument strings.
  3092.  
  3093.  
  3094.  
  3095. EXTERNAL. The input strings is read from the console. If multiple templates are
  3096.  
  3097. supplied,each template will read a new string. This source option is the same
  3098.  
  3099. as PULL.
  3100.  
  3101.  
  3102.  
  3103. NUMERIC. The current numeric options are placed in a string in the order
  3104.  
  3105. DIGITS,FUZZ,and FORM,separated by a single space.
  3106.  
  3107.  
  3108.  
  3109. PULL. Reads a string from the input console. If multiple templates are
  3110.  
  3111. supplied,each template will read a new string.
  3112.  
  3113.  
  3114.  
  3115. SOURCE. The "source" string for the program is retrieved. This string is
  3116.  
  3117. formatted as "{COMMAND | FUNCTION} {0 | 1} called resolved ext host." The first
  3118.  
  3119. token indicates whether the program was invoked as a command or as a function.
  3120.  
  3121. The second token is a boolean flag indicating whether a result string was
  3122.  
  3123. requested by the caller. The called token is the name used to invoke this
  3124.  
  3125. program,while the resolved token is the final resolved name of the program. The
  3126.  
  3127. ext token is the file extension to be used for searching(the default is
  3128.  
  3129. "REXX"). Finally,the host token is the initial host address for commands.
  3130.  
  3131.  
  3132.  
  3133. VALUE expression WITH. The input string is the result of the supplied
  3134.  
  3135. expression. The WITH keyword is required to separate the expression from the
  3136.  
  3137. template. The expression result may be parsed repeatedly by using multiple
  3138.  
  3139. templates,but the expression is not reevaluated.
  3140.  
  3141.  
  3142.  
  3143. VAR variable. The value of the specified variable is used as the input string.
  3144.  
  3145. When multiple templates are provided,each template uses the current value of
  3146.  
  3147. the variable.
  3148.  
  3149.  
  3150.  
  3151.                                 33
  3152.  
  3153.  
  3154.  
  3155. This value may change if the variable is included as an assignment target in
  3156.  
  3157. any of the templates.
  3158.  
  3159.  
  3160.  
  3161. VERSION. The current configuation of the ARexx interpreter is supplied in the
  3162.  
  3163. form "ARexx version cpu mpu video freq". The version toekn is the release level
  3164.  
  3165. of the interpreter,formatted as V1.0. The cpu token indicates the processor
  3166.  
  3167. currently running the program,and will be one of the values 68000,68010,or
  3168.  
  3169. 68020. The mpu token will be either NONE or 68881 depending on whether a math
  3170.  
  3171. coprocessor is available on the system. The video token will indicate either
  3172.  
  3173. NTSC or PAL,and the freq token gives the clock(line)frequency as either 60HZ or
  3174.  
  3175. 50 HZ.
  3176.  
  3177.  
  3178.  
  3179. TEMPLATES
  3180.  
  3181.  
  3182.  
  3183. Parsing is controlled by a template,which may consist of symbols,strings,
  3184.  
  3185. operators,and parentheses. During the parsing operation the input string is
  3186.  
  3187. split into substrings that are assigned to the variable symbols in the
  3188.  
  3189. template. The process continues until all of the variables in the template have
  3190.  
  3191. been assigned a value;if the input string is "used up",any remaining variables
  3192.  
  3193. are given null values.
  3194.  
  3195.  
  3196.  
  3197. Templates are described in depth in Chapter 8,so only a simplified description
  3198.  
  3199. is presented here. The goal of the parsing operation is to associate a
  3200.  
  3201. "current" and "next" position with each variable symbol in the template. The
  3202.  
  3203. substring between these positions is then assigned as the value to the
  3204.  
  3205. variable. There are three basic methods used to determine the value strings.
  3206.  
  3207.  
  3208.  
  3209. PARSING BY TOKENIZATION. When a variable in the template is followed
  3210.  
  3211. immediately by another variable,the value string is determined by breaking the
  3212.  
  3213. input string into words separated by blanks. Each word is assigned to a
  3214.  
  3215. variable in the template.
  3216.  
  3217.  
  3218.  
  3219. Values determined by tokenization will never have leading or trailing blanks.
  3220.  
  3221. Normally the last variable in the template receives the untokenized remainder
  3222.  
  3223. of the input string,since it is not followed by a symbol. A "placeholder"
  3224.  
  3225. symbol,signified by a period(.),may be used to force tokenization. Placeholders
  3226.  
  3227. behave like variables in the template except that they are never actually
  3228.  
  3229. assigned a value.
  3230.  
  3231. Example:
  3232.  
  3233.  
  3234.  
  3235.         /* Numeric string is: "9 0 SCIENTIFIC"  */
  3236.  
  3237.         parse numberic digits fuzz form .
  3238.  
  3239.         say digits              /* =>9                  */
  3240.  
  3241.         say fuzz                /* =>0                  */
  3242.  
  3243.         say from                /*=> SCEIENTIFIC        */
  3244.  
  3245.  
  3246.  
  3247. PARSING BY POSITION. If the fields in the input string have known positions,
  3248.  
  3249. value strings can be specified by absolute or relative positions. Relative
  3250.  
  3251. positions are indicated by a number preceded by a "+" or "-" operator. Each
  3252.  
  3253. positional marker updates the scan position in the string. The value assigned
  3254.  
  3255. to a variable is the string from the current position up to,but not including,
  3256.  
  3257. the next position in the string.
  3258.  
  3259.  
  3260.  
  3261.                                 34
  3262.  
  3263.  
  3264.  
  3265. Example:
  3266.  
  3267.  
  3268.  
  3269.         /* assume argument is "1234567890"              */
  3270.  
  3271.         parse arg 1 a 3 b +2 1 c
  3272.  
  3273.         say a b c               /* ==> 12 34 1234567890 */
  3274.  
  3275.  
  3276.  
  3277. PARSING WITH PATTERNS. Fields in the input string separated by specific
  3278.  
  3279. characters or strings can be parsed using a pattern,which is matched against
  3280.  
  3281. the input string. A pattern is specified in the template as a string token,or
  3282.  
  3283. alternatively as a symbol enclosed in parentheses. The position in the parse
  3284.  
  3285. string matched by the pattern determines the value strings. The pattern is
  3286.  
  3287. removed from the input string when a match is found;this is the only parsing
  3288.  
  3289. operation that modifies the input string.
  3290.  
  3291. Example:
  3292.  
  3293.  
  3294.  
  3295.         check = 'one,two,three'
  3296.  
  3297.         parse var check a ',' b ',' c
  3298.  
  3299.         say a b c       /* ==> one two three    */
  3300.  
  3301.  
  3302.  
  3303. PROCEDURE
  3304.  
  3305.  
  3306.  
  3307. Usage:PROCEDURE [EXPOSE variable [variable...]]
  3308.  
  3309. The PROCEDURE instruction is used within an internal function to create a new
  3310.  
  3311. symbol table. This protects the symbols defined in the caller's environment
  3312.  
  3313. from being altered by the execution of the function. PROCEDURE is usually the
  3314.  
  3315. first statement within the function,although it is valid anywhere withing the
  3316.  
  3317. function body. It is an error to execute two PROCEDURE statements within the
  3318.  
  3319. function.
  3320.  
  3321.  
  3322.  
  3323. EXPOSING VARIABLES. The EXPOSE subkeyword provides a selective mechanism for
  3324.  
  3325. accessing the caller's symbol table,and for passing global variables to a
  3326.  
  3327. function. The variables following the EXPOSE keyword are taken to refer to
  3328.  
  3329. symbols in the caller's table. Any subsequent changes made to these variables
  3330.  
  3331. will be reflected in the caller's environment.
  3332.  
  3333.  
  3334.  
  3335. The variables in the EXPOSE list may include stems or compound symbols,in which
  3336.  
  3337. case the ordering of the variables becomes significant. The EXPOSE list is
  3338.  
  3339. processed from left to right,and compound symbols are expanded based on the
  3340.  
  3341. values in effect in the new generation. For example,suppose that the value of
  3342.  
  3343. the symbol J in the previous gneration is 123,and that J is unitialized in the
  3344.  
  3345. new generation. Then PROCEDURE EXPOSE J A.J will expose J and A.123,whereas
  3346.  
  3347. PROCEDURE EXPOSE A.J J will expose A. J. and J. Exposing a stem has the effect
  3348.  
  3349. of exposing all possible compound symbols derived from that stem.
  3350.  
  3351. Example:
  3352.  
  3353.  
  3354.  
  3355.         fact: procedure         /* a recursive function */
  3356.  
  3357.            arg i
  3358.  
  3359.            if i <=1
  3360.  
  3361.               then return 1
  3362.  
  3363.               else return i*fact(i-1)
  3364.  
  3365.  
  3366.  
  3367.                                 35
  3368.  
  3369.  
  3370.  
  3371. Usage:PULL [template] [,template...]
  3372.  
  3373. This is a shorthand form of the PARSE UPPER PULL instruction. It reads a string
  3374.  
  3375. from the input console,translates it to uppercase,and parses it using the
  3376.  
  3377. template. Multiple strings can be ready by supplying additional templates. The
  3378.  
  3379. instruction will read from the console even if no template is given.
  3380.  
  3381.  
  3382.  
  3383. Templates are described briefly with the PARSE instruction and in greater depth
  3384.  
  3385. in Chapter 8.
  3386.  
  3387. Example:
  3388.  
  3389.  
  3390.  
  3391.         pull first last.        /* read names           */
  3392.  
  3393.  
  3394.  
  3395. PUSH
  3396.  
  3397.  
  3398.  
  3399. Usage: PUSH [expression]
  3400.  
  3401. The PUSH instruction is used to prepare a stream of data to be ready by a
  3402.  
  3403. command shell or other program. It appends a "newline" to the result of the
  3404.  
  3405. expression and then stacks or "pushes" it into the STDIN stream. Stacked lines
  3406.  
  3407. are placed in the stream in "last-in, first-out" order,and are then available
  3408.  
  3409. to be ready just as though they had been entered interactively. For example,
  3410.  
  3411. after issuing the instructions
  3412.  
  3413.  
  3414.  
  3415.         push line 1
  3416.  
  3417.         push line 2
  3418.  
  3419.         push line 3
  3420.  
  3421.  
  3422.  
  3423. the steam would be read in the order "line 3," "line 2" and "line 1."
  3424.  
  3425.  
  3426.  
  3427. There are several restrictions governing the use of the PUSH instruction and
  3428.  
  3429. its alter ego QUEUE. These instructions use a special I/O mechanism to
  3430.  
  3431. accomplish their task,and as a result can be used only with an interactive
  3432.  
  3433. (stream-model) I/O device like a console or pipe. The stream must be managed by
  3434.  
  3435. with a DOS handler that supports the special ACTION_STACK (for PUSH) or
  3436.  
  3437. ACTION_QUEUE (for QUEUE) command.
  3438.  
  3439.  
  3440.  
  3441. PUSH allows the STDIN stream to be used as a private scratchpad to prepare data
  3442.  
  3443. for subsequent processing. For example,several files could be concatenated with
  3444.  
  3445. delimiters between them by simply reading the input files,PUSHing the lines
  3446.  
  3447. into the stream,and inserting a delimiter where required. Once the stacked
  3448.  
  3449. lines are exhausted,the stream reverts to its normal source of data.
  3450.  
  3451. Example:
  3452.  
  3453.  
  3454.  
  3455.         /* Stack commands for compile and link*/
  3456.  
  3457.         push "blink c.o+main.o library amiga.lib to myprog"
  3458.  
  3459.         push "cc main"
  3460.  
  3461.  
  3462.  
  3463.                                 36
  3464.  
  3465.  
  3466.  
  3467. QUEUE
  3468.  
  3469.  
  3470.  
  3471. Usage:QUEUE [expression]
  3472.  
  3473. The QUEUE instruction is used to prepare a stream of data to be read by a
  3474.  
  3475. command shell or other program. It is very similar to the preceding PUSH
  3476.  
  3477. instruction,and differs only that the data lines are placed in the STDIN stream
  3478.  
  3479. in "first-in,first-out" order. In this case the instruction
  3480.  
  3481.  
  3482.  
  3483.         queue line 1
  3484.  
  3485.         queue line 2
  3486.  
  3487.         queue line 3
  3488.  
  3489.  
  3490.  
  3491. would be read in the order "line 1," "line 2," and "line 3." The QUEUEd lines
  3492.  
  3493. always precede all interactivly-entered lines,and always follow any PUSHed
  3494.  
  3495. (stacked)lines.
  3496.  
  3497.  
  3498.  
  3499. The same restriction noted with the use of the PUSH instruction apply to the
  3500.  
  3501. QUEUE instruction. The queueing mechanism uses the ACTION_QUEUE command,so the
  3502.  
  3503. DOS handler associated with the STDIN stream must support this command.
  3504.  
  3505.  
  3506.  
  3507. In most cases the choice of whether to use PUSH or QUEUE is just a matter of
  3508.  
  3509. convenience or personal preference. Each of them provides a "scratch pad"
  3510.  
  3511. facility similar to that provided by an I/O pipe,but useful within one program
  3512.  
  3513. or task rather than just for interprocess communications.
  3514.  
  3515. Example:
  3516.  
  3517.  
  3518.  
  3519.         /* Queue commands for compile and link */
  3520.  
  3521.         queue "cc main"
  3522.  
  3523.         queue "blink c.o+main.o library amiga.lib to myprog"
  3524.  
  3525.  
  3526.  
  3527. RETURN
  3528.  
  3529. RETURN is used to leave a function and return control to the point of the
  3530.  
  3531. previous function invocation. The evaluated expression is returned as the
  3532.  
  3533. function result. If an expression is not supplied,an error may result in the
  3534.  
  3535. caller's environment. Functions called from within an expression must return a
  3536.  
  3537. result string,and will generate an error if no result is available. Function
  3538.  
  3539. invoked by the CALL instruction need not return a result.
  3540.  
  3541.  
  3542.  
  3543. A RETURN issued from the base environment of a program is not an error,and is
  3544.  
  3545. equivalent to an EXIT instruction. Refer to the EXIT instruction for a
  3546.  
  3547. description of how result strings are passed back to an external caller.
  3548.  
  3549. Example:
  3550.  
  3551.  
  3552.  
  3553.         return 6*7              /*the answer    */
  3554.  
  3555.  
  3556.  
  3557.                                 37
  3558.  
  3559.  
  3560.  
  3561. SAY
  3562.  
  3563.  
  3564.  
  3565. Usage:SAY [expression]
  3566.  
  3567. The result of the evaluated expression is written to the output console,with a
  3568.  
  3569. "newline" character appended. If the expression is omitted,a null string is
  3570.  
  3571. sent to the console.
  3572.  
  3573. Example:
  3574.  
  3575.  
  3576.  
  3577.         say 'The anwer is ' value
  3578.  
  3579.  
  3580.  
  3581. SELECT
  3582.  
  3583.  
  3584.  
  3585. Usage:SELECT
  3586.  
  3587. This instruction begins a group of instructions containing one or more WHEN
  3588.  
  3589. clauses and possibly a single OTHERWISE clause,each followed by a conditional
  3590.  
  3591. statement.
  3592.  
  3593.  
  3594.  
  3595. Only one of the conditional statements within the SELECT group will be
  3596.  
  3597. executed. Each WHEN statement is executed in succession until one succeeds;if
  3598.  
  3599. none succeeds,the OTHERWISE statement is executed. The SELECT range must be
  3600.  
  3601. terminated by an eventual END statement.
  3602.  
  3603. Example:
  3604.  
  3605.  
  3606.  
  3607.         select
  3608.  
  3609.                 when i=1 then say 'one'
  3610.  
  3611.                 when i=2 then say 'two'
  3612.  
  3613.                 otherwise say 'other'
  3614.  
  3615.                 end
  3616.  
  3617.  
  3618.  
  3619. SHELL
  3620.  
  3621.  
  3622.  
  3623. Usage:SHELL [symbol | string] [expression]
  3624.  
  3625. The SHELL instruction is a synonym for the ADDRESS instruction.
  3626.  
  3627. Example:
  3628.  
  3629.  
  3630.  
  3631.         shell edit      /* set host to 'EDIT'   */
  3632.  
  3633.  
  3634.  
  3635. SIGNAL
  3636.  
  3637.  
  3638.  
  3639. Usage: SIGNAL {ON |OFF} condition
  3640.  
  3641.    or: SIGNAL [VALUE] expression
  3642.  
  3643. There are two forms of the SIGNAL instruction. The first form illustrated
  3644.  
  3645. controls the state of the internal interrupt flags. Interrupts allow a program
  3646.  
  3647. to detect and retain control when certain errors occur,and are discussed in
  3648.  
  3649. Chapter 7. In this form SIGNAL must be followed by one of the keywords ON or
  3650.  
  3651. OFF and one of the condition keywords listed below. The interrupt flag
  3652.  
  3653. specified by the condition symbol is then set to the indicated state. The valid
  3654.  
  3655. signal conditions are:
  3656.  
  3657.  
  3658.  
  3659. BREAK_C  A "control-C" break was detected.
  3660.  
  3661. BREAK_D  A "control-D" break was detected.
  3662.  
  3663. BREAK_E  A "control-E" break was detected.
  3664.  
  3665.  
  3666.  
  3667.                                 38
  3668.  
  3669.  
  3670.  
  3671. BREAK_F A "control-F" break was detected.
  3672.  
  3673. ERROR A Host command returned a non-zero code.
  3674.  
  3675. HALT  An external HALT request was detected.
  3676.  
  3677. IOERR An error was detected by the I/O system.
  3678.  
  3679. NOVALUE An uninitialized variable was used.
  3680.  
  3681. SYNTAX  A syntax or execution error was detected.
  3682.  
  3683.  
  3684.  
  3685. The condition keywords are interpreted as labels to which control will
  3686.  
  3687. transferred if the selected condition occurs. For example,if the ERROR
  3688.  
  3689. interrupt is enabled and a command returns a non-zero code,the interpreter will
  3690.  
  3691. transfer control to the label ERROR:. The condition label must of course be
  3692.  
  3693. defined in the program;otherwise,an immediate SYNTAX error results and the
  3694.  
  3695. program exits.
  3696.  
  3697.  
  3698.  
  3699. In the second form of the instruction,the tokens following SIGNAL are evaluated
  3700.  
  3701. as an expression. An immediate interrupt is generated that transfers control to
  3702.  
  3703. the label specified by the expression result. The instruction thus acts as a
  3704.  
  3705. "computed goto."
  3706.  
  3707.  
  3708.  
  3709. INTERRUPTS. Whenever an interrupt occurs,all currently active control ranges
  3710.  
  3711. (IF,DO,SELECT,INTERPRET,or interactive TRACE) are dismantled before the
  3712.  
  3713. transfer of control. Thus,the transfer cannot be used to jump into the range of
  3714.  
  3715. a DO-loop or other control structure. Only the control structures in the
  3716.  
  3717. current environment are affected by a SIGNAL condition,so it is safe to SIGNAL
  3718.  
  3719. from within an internal function without affecting the state of the caller's
  3720.  
  3721. environment.
  3722.  
  3723.  
  3724.  
  3725. SPECIAL VARIABLES. The special variable SIGL is set to the current line number
  3726.  
  3727. whenever a transfer of control occurs. The program can inspect SIGL to
  3728.  
  3729. determine which line was being executed before the transfer. If an ERROR or
  3730.  
  3731. SYNTAX condition causes an interrupt,the special variable RC is set to the
  3732.  
  3733. error code that triggered the interrupt. For the ERROR condition,this code is
  3734.  
  3735. usually an error secerity level. The SYNTAX condition will always indicate an
  3736.  
  3737. ARexx error code.
  3738.  
  3739. Examples:
  3740.  
  3741.  
  3742.  
  3743.         signal on error         /* enable interrupt     */
  3744.  
  3745.         signal off syntax       /* disable SYNTAX       */
  3746.  
  3747.         signal start            /* goto START           */
  3748.  
  3749.  
  3750.  
  3751. THEN
  3752.  
  3753.  
  3754.  
  3755. Usage:THEN[;] [conditional statement]
  3756.  
  3757. The THEN instruction must be the next statement following an IF or WHEN
  3758.  
  3759. instruction,and is valid only in that context. It tests whether the preceding
  3760.  
  3761. expression evaluated to 1(True),in which case the conditional statement
  3762.  
  3763. following the THEN is performed. If the expression result was a 0(False),the
  3764.  
  3765. conditional statement is skipped.
  3766.  
  3767.  
  3768.  
  3769.                                 39
  3770.  
  3771.  
  3772.  
  3773. Example:
  3774.  
  3775.  
  3776.  
  3777.         if i=j
  3778.  
  3779.            then say 'equal'
  3780.  
  3781.            else say 'not equal'
  3782.  
  3783.  
  3784.  
  3785. TRACE
  3786.  
  3787.  
  3788.  
  3789. Usage:TRACE [symbol|string|[[VALUE] expression]]
  3790.  
  3791. The TRACE instruction is used to set the internal tracing mode. If a symbol or
  3792.  
  3793. string is supplied,it is taken as a literal. Otherwise,the tokens following the
  3794.  
  3795. VALUE keyword are evaluated as an expression. The VALUE keyword can be omitted
  3796.  
  3797. if the expression doesn't start with a symbol or string token.
  3798.  
  3799.  
  3800.  
  3801. In either case the result string is converted to uppercase and checked first
  3802.  
  3803. for one of the "alphabetic" options. The valid alphabetic options are ALL,
  3804.  
  3805. COMMANDS,ERRORS,INTERMEDIATES,LABELS,RESULTS,and SCAN. These can be spelled out
  3806.  
  3807. in full or shortened to the initial character,and are described in Chapter 7.
  3808.  
  3809. If the result doesn't match any of these options,the interpreter attempts to
  3810.  
  3811. convert it to an integer. A conversion failure here will be reported as an
  3812.  
  3813. error.
  3814.  
  3815.  
  3816.  
  3817. PREFIX CHARACTERS. Two special symbol characters may precede any of the
  3818.  
  3819. alphabetic keywords. The "?" character interactive tracing,and the "!"
  3820.  
  3821. character controls command inhibition. These characters act as "toggles" to
  3822.  
  3823. alternatively select and de-select the respective modes. Any number of prefix
  3824.  
  3825. characters may precede an alphabetic option. Interactive tracing and command
  3826.  
  3827. inhibition are described in Chapter 7.
  3828.  
  3829.  
  3830.  
  3831. NUMERIC OPTION. If the specified trace option is a negative whole number,it is
  3832.  
  3833. accepted as a trace suppression count. The suppression count is the number of
  3834.  
  3835. clauses(that would otherwise be traced)to be passed over before resuming the
  3836.  
  3837. tracing display. Suppression counts are ignored execept during interactive
  3838.  
  3839. tracing.
  3840.  
  3841. Examples:
  3842.  
  3843.  
  3844.  
  3845.         trace ?r                /* interactive RESULTS  */
  3846.  
  3847.         trace off
  3848.  
  3849.         trace -20               /* skip 20 clauses      */
  3850.  
  3851.  
  3852.  
  3853. UPPER
  3854.  
  3855.  
  3856.  
  3857. Usage:UPPER variable [variable...]
  3858.  
  3859. The values of the variables in the list are converted to uppercase. It is not
  3860.  
  3861. an error to include an uninitialized variable in the list,but it will be
  3862.  
  3863. trapped if the NOVALUE interrupt has been enabled.
  3864.  
  3865.  
  3866.  
  3867. The TRANSLATE() or UPPER() Built-In functions could also be used to convert
  3868.  
  3869. variables to uppercase,but the instruction form is more concise(and faster) if
  3870.  
  3871. several variables are being converted.
  3872.  
  3873.  
  3874.  
  3875.                                 40
  3876.  
  3877.  
  3878.  
  3879. Example:
  3880.  
  3881.  
  3882.  
  3883.         when='Now is the time'
  3884.  
  3885.         upper when
  3886.  
  3887.         say when                /* NOW IS THE TIME      */
  3888.  
  3889.  
  3890.  
  3891. WHEN
  3892.  
  3893.  
  3894.  
  3895. Usage:WHEN expression [THEN [;] [conditional statement]]
  3896.  
  3897. The WHEN instruction is similar to the IF instruction,but is valid only within
  3898.  
  3899. a SELECT range. Each WHEN expression is evaluated in turn and must result in a
  3900.  
  3901. boolean value. If the result is a 1,the conditional statement is executed and
  3902.  
  3903. control passes to the END statement that terminates the SELECT. As in the case
  3904.  
  3905. of the IF instruction,the THEN need not be part of the same clause.
  3906.  
  3907. Example:
  3908.  
  3909.  
  3910.  
  3911.         select;
  3912.  
  3913.            when i<j thn say 'less'
  3914.  
  3915.            when i=j then say 'equal'
  3916.  
  3917.            otherwise     say 'greater'
  3918.  
  3919.            end
  3920.  
  3921.  
  3922.  
  3923.                                 41
  3924.  
  3925.  
  3926.  
  3927.                           CHAPTER 5  COMMANDS
  3928.  
  3929.  
  3930.  
  3931. The REXX language is unusual in that an entire syntactic class of program
  3932.  
  3933. statements are reserved for cmmands,statements that have meaning not within the
  3934.  
  3935. language itself but rather to an external program. When a command clause is
  3936.  
  3937. found in a program,it is evaluated as an expression and then sent through the
  3938.  
  3939. command interface to an explicit or implicit host application,an external
  3940.  
  3941. program that has announced its ability to receive commands. The host
  3942.  
  3943. application then processes the command and returns a result code that indicates
  3944.  
  3945. whether the command was performed successfully. In this manner every host
  3946.  
  3947. program becomes fully programmable,and with even a limited set of predefined
  3948.  
  3949. operations can be customized by the end user.
  3950.  
  3951.  
  3952.  
  3953. This chapter discusses the ARexx command interface and examines some of the
  3954.  
  3955. ways in which commands can be used to build programs for an external program.
  3956.  
  3957. Such programs are ofter called "macro programs" because they implement a
  3958.  
  3959. complex ("macro") action from a series of simpler "micro" commands.
  3960.  
  3961.  
  3962.  
  3963. Chapter 10 has detailed information on the data structers required to implement
  3964.  
  3965. a command interface for an applications program.
  3966.  
  3967.  
  3968.  
  3969. COMMAND CLAUSES
  3970.  
  3971.  
  3972.  
  3973. Syntactically,a command clause is just an expression that can't be classified
  3974.  
  3975. as another type of clause. The actual structure of the command is dictated by
  3976.  
  3977. the external host to which it is intended,but in most cases will follow the
  3978.  
  3979. model of a name or letter followed by parameter data. Command names can be
  3980.  
  3981. given as either a symbol or a string. However,it is generally safer to use a
  3982.  
  3983. string for the name,since it can't be assigned a value or be mistaken for an
  3984.  
  3985. instruction keyword. For example,the following might be commands for a text
  3986.  
  3987. editor:
  3988.  
  3989.  
  3990.  
  3991.         JUMP current+10         /* advance to next      */
  3992.  
  3993.         'insert' newstring      /* blast it in          */
  3994.  
  3995.         'TOP'                   /* back to the top      */
  3996.  
  3997.  
  3998.  
  3999. Since command clauses are expressions,they are fully evaluated before being
  4000.  
  4001. sent to the host. Any part of the final command string can be computed within
  4002.  
  4003. the program,so virtually any sort of command structure can be created.
  4004.  
  4005.  
  4006.  
  4007. The interpretation of the received commands depends entirely on the host
  4008.  
  4009. application. In the simplest case the command strings will correspond exactly
  4010.  
  4011. to commands that could be entered directly by a user. For instance,positional
  4012.  
  4013. control(up/down)commands for a text editor would probably have identical
  4014.  
  4015. interpretations whether issued by the user or from a program. Other commands
  4016.  
  4017. may be valid only when issued from a macro program;a command to simulate a menu
  4018.  
  4019. operation would probably not be entered by the user.
  4020.  
  4021.  
  4022.  
  4023.                                 43
  4024.  
  4025.  
  4026.  
  4027. THE HOST ADDRESS
  4028.  
  4029.  
  4030.  
  4031. The destination for a command is determined by the current host address,which
  4032.  
  4033. is the name of the public message port managed by an external program. ARexx
  4034.  
  4035. maintains two implicit host addresses,a "current" and a "previous" value,as
  4036.  
  4037. part of the program's storage environment. These values can be changed at any
  4038.  
  4039. time using the ADDRESS instruction(or its synonym,SHELL,)and the current host
  4040.  
  4041. address can be inspected with the ADDRESS()Built-In fuction. The default host
  4042.  
  4043. address string is "REXX",but this can be overridden when a program is invoked.
  4044.  
  4045. In particular,most host applications will supply the name of their public port
  4046.  
  4047. when they invoke a macro program,so that the macro can automatically issue
  4048.  
  4049. commands back to the host.
  4050.  
  4051.  
  4052.  
  4053. One special host address is recognized: the string COMMAND indicates that the
  4054.  
  4055. command should be issued directly to the underlying DOS. All other host
  4056.  
  4057. addresses are assumed to refer to a public message port. An attempt to send a
  4058.  
  4059. commmand to a non-existent message port will generate the syntax error "Host
  4060.  
  4061. environment not found."
  4062.  
  4063.  
  4064.  
  4065. Single commands can be sent to a specific host without disturbing the host
  4066.  
  4067. address settings. This is done using the ADDRESS instruction,as the following
  4068.  
  4069. example illustrates:
  4070.  
  4071.  
  4072.  
  4073. ADDRESS MYEDIT 'jump top'
  4074.  
  4075.  
  4076.  
  4077. This example would send the command "jump top" to an external host named
  4078.  
  4079. "MYEDIT."
  4080.  
  4081.  
  4082.  
  4083. It is important to note that you cannot send commands to a host application
  4084.  
  4085. without knowing the name of its public message port. Writing macro programs to
  4086.  
  4087. communicate with two or more hosts may require some clever programming to
  4088.  
  4089. determine whether both hosts are active and what their respective host
  4090.  
  4091. addresses are.
  4092.  
  4093.  
  4094.  
  4095. THE COMMAND INTERFACE
  4096.  
  4097.  
  4098.  
  4099. ARexx implements its command interface using the message-passing facilities
  4100.  
  4101. provided by the EXEC operating system. Each host application must provide a
  4102.  
  4103. public message port,the name of which is referred to as the host address. ARexx
  4104.  
  4105. programs issue commands by placing the command string in a message packet and
  4106.  
  4107. sending the packet to the host's message port. The program "sleeps" while the
  4108.  
  4109. host processes the command,and awakens when the message packet returns. The
  4110.  
  4111. entire process can be regarded as a dialogue between the host application and a
  4112.  
  4113. macro program:the host initiates the dialogue by invoking the macro,and the
  4114.  
  4115. macro program replies with one or more command strings. The commands that can
  4116.  
  4117. be sent are not limited to simple text strings,but might be address pointers or
  4118.  
  4119. even bit-mapped images.
  4120.  
  4121.  
  4122.  
  4123. After it finishes processing a command,the host "replies" the message packet
  4124.  
  4125. with a return code that indicates the status of the command. This return code
  4126.  
  4127. is placed in the ARexx special variable RC so that it can be examined by the
  4128.  
  4129. program. A value of zero is assumed to mean that no errors occurred,while
  4130.  
  4131. positive values usually indicate progressively more severe error conditions.
  4132.  
  4133. The return code allows the macro program to determine whether the command
  4134.  
  4135. succeeded and to take action if it failed,so it is important for each
  4136.  
  4137. applictions program to document the meanings of the return codes for its
  4138.  
  4139. commands.
  4140.  
  4141.  
  4142.  
  4143.                                 44
  4144.  
  4145.  
  4146.  
  4147. USING COMMANDS IN MACRO PROGRAMS
  4148.  
  4149.  
  4150.  
  4151. ARexx can be used to write programs for any host application that includes a
  4152.  
  4153. suitable command interface. Some applications programs are designed with an
  4154.  
  4155. embedded macro language,and may include many predefined macro commands. With a
  4156.  
  4157. well-designed macro language interface the user will be usually unaware of
  4158.  
  4159. whether a given action is implemented as a primitive operations or as a macro
  4160.  
  4161. program.
  4162.  
  4163.  
  4164.  
  4165. The starting point in designing a macro program is to examine the commands that
  4166.  
  4167. would be required to perform it manually. The documentation for the host
  4168.  
  4169. application program should then describe the possible return codes for each
  4170.  
  4171. command;these codes can be used to determine whether the operation performed by
  4172.  
  4173. the command was successful. Check also for "shortcut" commands that may be
  4174.  
  4175. available only to macro programs;some applications programs may include very
  4176.  
  4177. powerful functions that were implemented specifically for use in macro
  4178.  
  4179. programs.
  4180.  
  4181.  
  4182.  
  4183. USING AREXX WITH COMMAND SHELLS
  4184.  
  4185.  
  4186.  
  4187. Although ARexx was designed to work most effectively with programs that support
  4188.  
  4189. its specific command interface,it can be used with any "command shell" program
  4190.  
  4191. that uses standards I/O mechanisms to obtain its input stream. There are
  4192.  
  4193. several ways to use ARexx to prepare a stream of commands for such program.
  4194.  
  4195.  
  4196.  
  4197. One obvious technique is to create an actual command file on the "RAM:" disk
  4198.  
  4199. and then pass it directly to the command shell. For example,you could open a
  4200.  
  4201. new CLI window to run a standard "execute" script using the following short
  4202.  
  4203. program:
  4204.  
  4205.  
  4206.  
  4207.         /* Launch a new CLI     */
  4208.  
  4209.         address command
  4210.  
  4211.         conwindow = "CON:0/0/640/100/NewOne"
  4212.  
  4213.  
  4214.  
  4215.         /* create a command file on the fly  */
  4216.  
  4217.         call open out,"ram:$$temp",write
  4218.  
  4219.         call writeln out,'echo "this is a test"'
  4220.  
  4221.         call close out
  4222.  
  4223.  
  4224.  
  4225.         /* open the new CLI window */
  4226.  
  4227.         'newcli' conwindow "ram:$$temp"'
  4228.  
  4229.         exit
  4230.  
  4231.  
  4232.  
  4233. Since no disk accesses are required,this method is actually fairly fast,if not
  4234.  
  4235. very elegant.
  4236.  
  4237.  
  4238.  
  4239. Another alternative is to use the command stacking facility provided by the
  4240.  
  4241. PUSH and QUEUE instructions. These instructions allow an ARexx program to stack
  4242.  
  4243. an arbitrary stream of commands and data for the command shell or other program
  4244.  
  4245. to read. Any set of commands that could be "typed ahead" at a command prompt
  4246.  
  4247. can be prepared in this fashion. After the ARexx program exits,the next program
  4248.  
  4249. that uses the input stream will read the prepared commands and can process them
  4250.  
  4251. in the normal fashion.
  4252.  
  4253.  
  4254.  
  4255.                                 45
  4256.  
  4257.  
  4258.  
  4259. COMMAND INHIBITION
  4260.  
  4261.  
  4262.  
  4263. Sometimes it is necessary to write and test macro programs that issue
  4264.  
  4265. potentially destructive commands. For instance,a program to find and delete
  4266.  
  4267. unneeded files would be difficult to test safely,since it might accidentally
  4268.  
  4269. delete the wrong files and would require a continual source of new files for
  4270.  
  4271. testing.
  4272.  
  4273.  
  4274.  
  4275. To simply the development and testing of such programs,ARexx provides a special
  4276.  
  4277. tracing mode called command inhibition that suppresses host commands. While in
  4278.  
  4279. command inhibition mode,command processing proceeds normally except that the
  4280.  
  4281. command is not actually issued and the variable RC is set to 0. This allows the
  4282.  
  4283. program logic to be verified before any commands are actually sent to the
  4284.  
  4285. external program. Chapter 7 has further information on this facility.
  4286.  
  4287.  
  4288.  
  4289.                                 46
  4290.  
  4291.  
  4292.  
  4293.                            CHAPTER 6  FUNCTIONS
  4294.  
  4295.  
  4296.  
  4297. The basic concept of a function is a program or group of statements that will
  4298.  
  4299. be executed whenever the function name appears in a certain context. Functions
  4300.  
  4301. are an important building block of most computer languages in that they allow
  4302.  
  4303. modular programming -- the ability to build a large program from a series of
  4304.  
  4305. smaller,more easily developed modules. In ARexx a function may be defined as
  4306.  
  4307. part of(internal to)a program,as part of a library,or as a separate external
  4308.  
  4309. program.
  4310.  
  4311.  
  4312.  
  4313. SYNTAX AND SEARCH ORDER
  4314.  
  4315.  
  4316.  
  4317. Function calls in an expression are defined syntactically as a symbol or string
  4318.  
  4319. followed immediately by an open parenthesis. The symbol or string(taken an a
  4320.  
  4321. literal)specifies the function name,and the open parenthesis begins the
  4322.  
  4323. argument list. Between the opening and eventual closing parentheses are zero or
  4324.  
  4325. more argument expressions,separated by commas,that supply the data being passed
  4326.  
  4327. to the function. For example,
  4328.  
  4329.  
  4330.  
  4331.         CENTER('title",20)
  4332.  
  4333.         ADDRESS()
  4334.  
  4335.         'AllocMem'(256*4,1)
  4336.  
  4337.  
  4338.  
  4339. are all valid function calls. Each argument expression is evaluated in turn and
  4340.  
  4341. the resulting strings are passed as the argument list to the function. There is
  4342.  
  4343. no limit to the number of arguments that may be passed to an internal
  4344.  
  4345. function,but calls to Built-In or external functions are limited to a maximum
  4346.  
  4347. of 15 arguments. Note that each argument expression,while ofter just a single
  4348.  
  4349. literal value,can include arithmetic or string operations or even other
  4350.  
  4351. function calls. Argument expressions are evaluated from left to right.
  4352.  
  4353.  
  4354.  
  4355. Functions can also be invoked using the CALL instruction. The syntax of this
  4356.  
  4357. form is slightly different,and is described in Chapter 4. The CALL instruction
  4358.  
  4359. can be used to invoke a function that may not return a value.
  4360.  
  4361.  
  4362.  
  4363. SEARCH ORDER
  4364.  
  4365.  
  4366.  
  4367. Function linkages in ARexx are established dynamically at the time of the
  4368.  
  4369. function call. A specific search order is followed until a function matching
  4370.  
  4371. the name symbol or string is found. If the specified function cannot be
  4372.  
  4373. located, an error is generated and the expression evaluation is terminated. The
  4374.  
  4375. full search order is:
  4376.  
  4377.  
  4378.  
  4379. 1. Internal Functions. The program source is examined for a label that matches
  4380.  
  4381. the function name. If a match is found,a new storage environment is created and
  4382.  
  4383. control is transferred to the label.
  4384.  
  4385.  
  4386.  
  4387. 2. Built-In Functions. The Build-In function library is searched for the
  4388.  
  4389. specified name. All of these functions are defined by uppercase names,and the
  4390.  
  4391. library has been specially organized to make the search as efficient as
  4392.  
  4393. possible.
  4394.  
  4395.  
  4396.  
  4397.                                 47
  4398.  
  4399.  
  4400.  
  4401. 3. Function Libraries and Function Hosts. The available function libraries and
  4402.  
  4403. function hosts are maintained in a prioritized list,which is searched starting
  4404.  
  4405. at the highest priority until the requested function is found or the end of the
  4406.  
  4407. list is reached. Each function library is opened and called at a special entry
  4408.  
  4409. point to determine whether it contains a function matching the given name.
  4410.  
  4411. Function hosts are called using a message-passing protocol similar to that used
  4412.  
  4413. for commands,and may be used as gateways for remote procedure calls to other
  4414.  
  4415. machines in a network.
  4416.  
  4417.  
  4418.  
  4419. 4. External ARexx Programs. The final search step is to check for an external
  4420.  
  4421. ARexx program file by sending an invocation message to the ARexx resident
  4422.  
  4423. process. The search always begins in the current directory,and follows the same
  4424.  
  4425. search path as the original ARexx program invocation. The name matching process
  4426.  
  4427. is not case-sensitive.
  4428.  
  4429.  
  4430.  
  4431. Note that the function name-matching procedure may be case-sensitive for some
  4432.  
  4433. of the search steps but not for others. The matching procedure used in a
  4434.  
  4435. function library or function host is left to the discretion of the applications
  4436.  
  4437. designer. Functions defined with mixed-case names must be called using a string
  4438.  
  4439. token,since symbol names are always translated to uppercase.
  4440.  
  4441.  
  4442.  
  4443. The full search order is followed whenever the function name is defined by a
  4444.  
  4445. symbol token. However,the search for internal functions is bypassed if the name
  4446.  
  4447. is specified by a string token. This allows internal functions to usurp the
  4448.  
  4449. names of external functions,as in the following example:
  4450.  
  4451.  
  4452.  
  4453. CENTER:                         /* internal "CENTER" */
  4454.  
  4455. arg string,length               /* get arguments     */
  4456.  
  4457. length = min(length,60)         /* compute length    */
  4458.  
  4459. return 'CENTER'(string,length)
  4460.  
  4461.  
  4462.  
  4463. Here the Built-In fuction CENTER()has been replaced by an internal function of
  4464.  
  4465. the same name,which calls the original function after modifying the length
  4466.  
  4467. argument.
  4468.  
  4469.  
  4470.  
  4471. INTERNAL FUNCTIONS
  4472.  
  4473.  
  4474.  
  4475. The interpreter creates a new storage environment when an internal function is
  4476.  
  4477. called,so that the previous(caller's)environment is preserved. The new
  4478.  
  4479. environment inherits the values from its predecessor,but subsequent changes to
  4480.  
  4481. the environment variables do not affect the previous environment. The specific
  4482.  
  4483. values that are preserved are:
  4484.  
  4485.  
  4486.  
  4487. The current and previous host addresses,
  4488.  
  4489. The NUMERIC DIGITS,FUZZ,and FORM settings,
  4490.  
  4491. The trace option,inhibit flag,and interace flag,
  4492.  
  4493. The state of the interrupt flags defined by the SIGNAL instruction,and
  4494.  
  4495. The current prompt string as set by the OPTIONS PROMPT instruction.
  4496.  
  4497.  
  4498.  
  4499. The new environment does not automatically get a new symbol table,so initially
  4500.  
  4501. all of the variables in the previous environment are available to the called
  4502.  
  4503. function. The PROCEDURE instruction can be used to create a new symbol table
  4504.  
  4505.  
  4506.  
  4507.                                 48
  4508.  
  4509.  
  4510.  
  4511. and thereby protect the caller's symbol values.
  4512.  
  4513.  
  4514.  
  4515. Execution of the internal function proceeds until a RETURN instruction is
  4516.  
  4517. executed. At this point the new environment is dismantled and control resumes
  4518.  
  4519. at the point of the function call. The expression supplied with the RETURN
  4520.  
  4521. instruction is evaluated and passed back to the caller as the fuction result.
  4522.  
  4523.  
  4524.  
  4525. BUILT-IN FUNCTIONS
  4526.  
  4527.  
  4528.  
  4529. ARexx provides a substantial library of predefined functions as part of the
  4530.  
  4531. language system. These functions are always available and have been optimized
  4532.  
  4533. to work with the internal data structures. In general the Built-In functions
  4534.  
  4535. execute much faster than an equivalent interpreted function,so their usage is
  4536.  
  4537. strongly recommended.
  4538.  
  4539.  
  4540.  
  4541. The Built-In Function Library is not user-extensible,but additional functions
  4542.  
  4543. will be included in later releases.
  4544.  
  4545.  
  4546.  
  4547. EXTERNAL FUNCTION LIBRARIES
  4548.  
  4549.  
  4550.  
  4551. External function libraries provide a mechanism with which users and
  4552.  
  4553. applications developers can extend the functionality of ARexx. A function
  4554.  
  4555. library is a collection of one or more functions together with a "query" entry
  4556.  
  4557. point that serves to match a name string with the appropriate function.
  4558.  
  4559. External function libraries are supported as standard Amiga shared libraries,
  4560.  
  4561. and may be either memory or disk-resident. Disk-resident libraries are loaded
  4562.  
  4563. and opened as needed.
  4564.  
  4565.  
  4566.  
  4567. The ARexx resident process maintains a list,called the Library List,of the
  4568.  
  4569. currently available function libraries and function hosts. Applications
  4570.  
  4571. programs can add or remove function libraries as required. The Library List is
  4572.  
  4573. maintained as a priority-sorted queue,and entries can be added at an
  4574.  
  4575. appropriate priority to control the function name resolution. Libraries with
  4576.  
  4577. higher priorities are searched first;within a given priority level,those
  4578.  
  4579. libraries added first are searched first.
  4580.  
  4581.  
  4582.  
  4583. During the search process the ARexx interpreter opens each library and calls
  4584.  
  4585. its "query" entry point. The query function must then check to see whether the
  4586.  
  4587. requested function name is in the library. If not,it returns a "function not
  4588.  
  4589. found" error code and the search continues with the next library in the list.
  4590.  
  4591. Function libraries are always closed after being checked so that the operatiing
  4592.  
  4593. system can reclaim the memory space if required. Once the requested function
  4594.  
  4595. has been found,it is called with the arguments passed by the interpreter,and
  4596.  
  4597. must return an error code and a result string.
  4598.  
  4599.  
  4600.  
  4601. The ARexx language system includes an external function library in a file
  4602.  
  4603. called "rexxsupport.library". It contains a number of Amiga-specific functions
  4604.  
  4605. and is described in Appendix D. Chapter 10 provides information on designing
  4606.  
  4607. and implementing function libraries.
  4608.  
  4609.  
  4610.  
  4611.                                 49
  4612.  
  4613.  
  4614.  
  4615. FUNCTION HOSTS
  4616.  
  4617.  
  4618.  
  4619. Function hosts are called by sending a function invocation message packet to
  4620.  
  4621. the public message port identified by the host's name. No constraints are
  4622.  
  4623. imposed on the iternal design of the host except that it must eventually return
  4624.  
  4625. the invocation message with an appropriate return code and result string. The
  4626.  
  4627. function call may result in a new program being loaded and run,or might even be
  4628.  
  4629. sent to a network handler as a remote procedure call.
  4630.  
  4631.  
  4632.  
  4633. The available function hosts,along with the function libraries,are contained in
  4634.  
  4635. the Library List maintained by the resident process. This list provides a
  4636.  
  4637. general mechanism for resolving function names in a priority-controlled manner.
  4638.  
  4639.  
  4640.  
  4641. The ARexx resident process is an example of a function host. It is added to the
  4642.  
  4643. Library List at a nominal priority of -60 when the resident process is started,
  4644.  
  4645. using the same name ("REXX")that is used for command invocations. When it
  4646.  
  4647. receives a function invocation packet,it searches for an external file matching
  4648.  
  4649. the function name,just as it would for a command invocation of the same name.
  4650.  
  4651. In particular,the search begins with the current directory and process is not
  4652.  
  4653. case-sensitive,but is affected by the presence of explicit directory
  4654.  
  4655. specifications or file extensions in the name string. The rules governing the
  4656.  
  4657. search for external programs are covered in Chapter 9.
  4658.  
  4659.  
  4660.  
  4661. External programs are always run as a separate process in the Amiga's
  4662.  
  4663. multitasking system. The calling program "sleeps" until the called function
  4664.  
  4665. finishes and the message packet returns. The result string and error code are
  4666.  
  4667. returned in the packet.
  4668.  
  4669.  
  4670.  
  4671. THE BUILT-IN FUNCTION LIBRARY
  4672.  
  4673.  
  4674.  
  4675. This section of the chapter is devoted to descriptions of the individual Built
  4676.  
  4677. In functions,which are listed alphabetically. Many of the functions have
  4678.  
  4679. optional as well as required arguments. The optional arguments are shown in
  4680.  
  4681. brackets,and generally have a default value that is used if the argument is
  4682.  
  4683. omitted.
  4684.  
  4685.  
  4686.  
  4687. MAXIMUM ARGUMENTS. While internal functions can be called with any number of
  4688.  
  4689. arguments,the Built-In functions(and external functions as well)are limited to
  4690.  
  4691. a maximum of 15 arguments.
  4692.  
  4693.  
  4694.  
  4695. PAD AND OPTION CHARACTERS. For functions that accept a "pad" character
  4696.  
  4697. argument,only the first character of the argument string is significant. If a
  4698.  
  4699. null string is supplied,the default padding character(usually a blank)will be
  4700.  
  4701. used. Similarly,where an option keyword is specified as an argument,only the
  4702.  
  4703. first character is significant. Option keywords may be given in uppercase or
  4704.  
  4705. lowercase.
  4706.  
  4707.  
  4708.  
  4709. I/O SUPPORT FUNCTIONS. ARexx provides functions for creating and manipulating
  4710.  
  4711. external DOS files. The functions available at the present time are OPEN(),
  4712.  
  4713. CLOSE(),READCH(),READLN(),WRITECH(),WRITELN(),EOF(),SEEK(),and EXISTS(). Files
  4714.  
  4715. are referenced by a "logical name," a case-sensitive name that is assigned to a
  4716.  
  4717. file when it is first opened.
  4718.  
  4719.  
  4720.  
  4721.                                 50
  4722.  
  4723.  
  4724.  
  4725. There is no limit to the number of files that may be open simultaneously,and
  4726.  
  4727. all open files are closed automatically when the program exits.
  4728.  
  4729.  
  4730.  
  4731. BIT-MANIPULATION FUNCTIONS. The functions BITCHG(),BITCLR(),BITCOMP(),BITSET(),
  4732.  
  4733. and BITTST() are provided to implement extended bit-testing on character
  4734.  
  4735. strings. These functions differ from similar string-manipulation functions in
  4736.  
  4737. that the elementary unit of comparison is the bit rather than the byte. Bit
  4738.  
  4739. number are defined such that bit 0 is the low-order bit of the rightmost byte
  4740.  
  4741. of the string.
  4742.  
  4743.  
  4744.  
  4745. ABBREV()
  4746.  
  4747.  
  4748.  
  4749. Usage:ABBREV(string1,string2,[length]
  4750.  
  4751. Returns a boolean value that indicates whether string2 is an abbreviation of
  4752.  
  4753. string1 with length greater than or equal to the specified length argument. The
  4754.  
  4755. default length is 0,so the null string is an acceptable abbreviation.
  4756.  
  4757. Example:
  4758.  
  4759.  
  4760.  
  4761.         say abbrev('fullname','ful'  ==>1
  4762.  
  4763.         say abbrev('almost','alm',4) ==>0
  4764.  
  4765.         say abbrev('any','')         ==>1
  4766.  
  4767.  
  4768.  
  4769. ABS()
  4770.  
  4771.  
  4772.  
  4773. Usage:ABS(number)
  4774.  
  4775. Returns the absolute value of the number argument,which must be numeric.
  4776.  
  4777. Examples:
  4778.  
  4779.  
  4780.  
  4781.         say abs(-5.35)                  ==>5.35
  4782.  
  4783.         say abs(10)                     ==>10
  4784.  
  4785.  
  4786.  
  4787. ADDLIB()
  4788.  
  4789.  
  4790.  
  4791. Usage ADDLIB(name,priority,[offset,version])
  4792.  
  4793. Adds a function library or a function host to the Library List maintained by
  4794.  
  4795. the resident process. The name argument specifies either the name of a function
  4796.  
  4797. library or the public message port associated with a function host. The name is
  4798.  
  4799. case-sensitive,and any libraries thus declared should reside in the system
  4800.  
  4801. LIBS: directory. The priority argument specifies the search priority and must
  4802.  
  4803. be an integer between 100 and -100,inclusive. The offset and version arguments
  4804.  
  4805. apply only to libraries. The offset is the integer offset to the library's
  4806.  
  4807. "query" entry point,and the version is an integer specifying the minimum
  4808.  
  4809. acceptable release level of the library.
  4810.  
  4811.  
  4812.  
  4813. The function returns a boolean result that indicates whether the operation was
  4814.  
  4815. successful. Note that if a library is specified,it is not actually opened at
  4816.  
  4817. this time;similarly,no check is performed as to whether a specified function
  4818.  
  4819. host port has been opened yet.
  4820.  
  4821. Example:
  4822.  
  4823.  
  4824.  
  4825.         say addlib("rexxsupport.library",0,-30,0)==>1
  4826.  
  4827.         call addlib "EtherNet",-20      /* a gateway */
  4828.  
  4829.  
  4830.  
  4831.                                 51
  4832.  
  4833.  
  4834.  
  4835. ADDRESS()
  4836.  
  4837.  
  4838.  
  4839. Usage:ADDRESS()
  4840.  
  4841. Returns the current host address string. The host address is the message port
  4842.  
  4843. to which commands will be sent. The SHOW()function can be used to check whether
  4844.  
  4845. the required external host is actually available.
  4846.  
  4847. See Also:SHOW()
  4848.  
  4849. Example:
  4850.  
  4851.  
  4852.  
  4853.         say address()           ==>REXX
  4854.  
  4855.  
  4856.  
  4857. ARG()
  4858.  
  4859.  
  4860.  
  4861. Usage:ARG([number],['Exists' | 'Omitted'])
  4862.  
  4863. ARG()returns the number of arguments supplied to the current environment. If
  4864.  
  4865. the number parameter alone is supplied,the corresponding argument string is
  4866.  
  4867. returned. If a number and one of the keywords Exists or Omitted is given,the
  4868.  
  4869. boolean return indicates the status of the corresponding argument. Note that
  4870.  
  4871. the existence or omission test does not indicate whether the string has a null
  4872.  
  4873. value,but only whether a string was supplied.
  4874.  
  4875. Examples:
  4876.  
  4877.  
  4878.  
  4879.         /* Assume arguments were: ('one,,10)            */
  4880.  
  4881.         say arg()                       ==>3
  4882.  
  4883.         say arg(1)                      ==>one
  4884.  
  4885.         say arg(2,'0')                  ==>1
  4886.  
  4887.  
  4888.  
  4889. B2C()
  4890.  
  4891.  
  4892.  
  4893. Usage:B2C(string)
  4894.  
  4895. Converts a string of binary digits(0,1)into the corresponding(packed)character
  4896.  
  4897. representation. The conversion is the same as though the argument string had
  4898.  
  4899. been specified as a literal binary string(e.g. '1010'B). Blanks are permitted
  4900.  
  4901. in the string,but only at byte boundaries. This function is particularly useful
  4902.  
  4903. for creating strings that are to be used as bit masks.
  4904.  
  4905. See also:X2C()
  4906.  
  4907. Examples:
  4908.  
  4909.  
  4910.  
  4911.         say b2c('00110011')             ==>3
  4912.  
  4913.         say b2c('01100001')             ==>a
  4914.  
  4915.  
  4916.  
  4917. BITAND()
  4918.  
  4919.  
  4920.  
  4921. Usage:BITAND(string1,string2,[pad])
  4922.  
  4923. The argument strings are logically ANDed together,with the length of the result
  4924.  
  4925. being the longer of the two operand strings. If a pad character is supplied,the
  4926.  
  4927. shorter string is padded on the right;otherwise,the operation terminates at the
  4928.  
  4929. end of the shorter string and the remainder of the longer string is appended to
  4930.  
  4931. the result.
  4932.  
  4933. Example:
  4934.  
  4935.  
  4936.  
  4937.         bitand('0313'x,'FFF0'x)         ==>'0310'x
  4938.  
  4939.  
  4940.  
  4941.                                 52
  4942.  
  4943.  
  4944.  
  4945. BITCHG()
  4946.  
  4947. Usage:BITCHG(string,bit)
  4948.  
  4949. Changes the state of the specified bit in the argument string. Bit numbers are
  4950.  
  4951. defined such that bit 0 is the low-order bit of the rightmost byte of the
  4952.  
  4953. string.
  4954.  
  4955. Example:
  4956.  
  4957.         bitchg('0313'x,4)               ==>'0303'x
  4958.  
  4959.  
  4960.  
  4961. BITCLR()
  4962.  
  4963. Usage:BITCLR(string,bit)
  4964.  
  4965. Clears(sets to zero)the specified bit in the argument string. Bit numbers are
  4966.  
  4967. defined such that bit 0 is the low-order bit of the rightmost byte of the
  4968.  
  4969. string.
  4970.  
  4971. Example:
  4972.  
  4973.         bitclr('0313'x,4)               ==>'0303'x
  4974.  
  4975.  
  4976.  
  4977. BITCOMP()
  4978.  
  4979. Usage:BITCOMP(string1,string2,[pad])
  4980.  
  4981. Compares the argument strings bit-by-bit,starting at bit number 0. The returned
  4982.  
  4983. value is the bit number of the first bit in which the strings differ,or -1 if
  4984.  
  4985. the strings are identical.
  4986.  
  4987. Examples:
  4988.  
  4989.         bitcomp('7F'x,'FF'x)            ==>7
  4990.  
  4991.         bitcomp('FF'x,'FF'x)            ==>-1
  4992.  
  4993.  
  4994.  
  4995. BITOR()
  4996.  
  4997. Usage:BITOR(string1,string2,[pad])
  4998.  
  4999. The argument strings are logically ORed together,with the length of the result
  5000.  
  5001. being the longer of the two operand strings. If a pad character is supplied,the
  5002.  
  5003. shorter string is padded on the right;otherwise,the operation terminates at the
  5004.  
  5005. end of the shorter string and the remainder of the longer string is appended to
  5006.  
  5007. the result.
  5008.  
  5009. Example:
  5010.  
  5011.         bitor('0313'x,'003F'x)          ==>'033F'x
  5012.  
  5013.  
  5014.  
  5015. BITSET()
  5016.  
  5017. Usage:BITSET(string,bit)
  5018.  
  5019. Sets the specified bit in the argument string is 1. Bit numbers are defined
  5020.  
  5021. such that bit 0 is the low-order bit of the rightmost byte of the string.
  5022.  
  5023. Example:
  5024.  
  5025.         bitset('0313'x,2)               ==>'0317'x
  5026.  
  5027.  
  5028.  
  5029. BITTST()
  5030.  
  5031. Usage:BITTST(string,bit)
  5032.  
  5033. The boolean return indicates the state of the specified bit in the argument
  5034.  
  5035. string.
  5036.  
  5037.  
  5038.  
  5039.                                 53
  5040.  
  5041.  
  5042.  
  5043. Bit numbers are defined such that bit 0 is the low-order bit of the rightmost
  5044.  
  5045. byte to the string.
  5046.  
  5047. Example:
  5048.  
  5049.         bittst('0313'x,4)               ==>1
  5050.  
  5051.  
  5052.  
  5053. BITXOR()
  5054.  
  5055. Usage:BITAND(string1,string2,[pad])
  5056.  
  5057. The argument strings are logically exclusively-ORed together,with the length of
  5058.  
  5059. the result being the longer of the two operand strings. If a pad character is
  5060.  
  5061. supplied,the shorter string is padded on the right;otherwise,the operation
  5062.  
  5063. terminates at the end of the shorter string and the remainder of the longer
  5064.  
  5065. string is appended to the result.
  5066.  
  5067. Example:
  5068.  
  5069.         bitxor('0313'x,'001F'x)         ==>'030C'x
  5070.  
  5071.  
  5072.  
  5073. C2B()
  5074.  
  5075. Usage:C2B(string)
  5076.  
  5077. Converts the character string into the equivalent string of binary digits.
  5078.  
  5079. See Also:C2X()
  5080.  
  5081. Example:
  5082.  
  5083.         say c2b('abc')                  ==>011000010110001001100011
  5084.  
  5085.  
  5086.  
  5087. C2D()
  5088.  
  5089. Usage:C2D(string,[n])
  5090.  
  5091. Converts the string argument from its character representation to the
  5092.  
  5093. corresponding decimal number,expressed as ASCII digits(0-9). If n is supplied,
  5094.  
  5095. the character string is considered to be a number expressed in n bytes. The
  5096.  
  5097. string is truncated or padded with nulls on the left as required,and the sign
  5098.  
  5099. bit is extended for the conversion.
  5100.  
  5101. Examples:
  5102.  
  5103.         say c2d('0020'x)                ==>32
  5104.  
  5105.         say c2d('FFFF')                 ==>1
  5106.  
  5107.         say c2d('FF0100',x,2)           ==>256
  5108.  
  5109.  
  5110.  
  5111. C2X()
  5112.  
  5113. Usage:C2X(string)
  5114.  
  5115. Converts the string argument from its character representation to the
  5116.  
  5117. corresponding hexadecimal number,expressed as the ACSII characters 0-9 and A-F.
  5118.  
  5119. See Also:C2B()
  5120.  
  5121. Example:
  5122.  
  5123.         say c2x('abc')                  ==>616263
  5124.  
  5125.  
  5126.  
  5127.                                 54
  5128.  
  5129.  
  5130.  
  5131. CENTER() or CENTRE()
  5132.  
  5133. Usage:CENTER(string,length,[pad])or CENTRE(string,length,[pad])
  5134.  
  5135. Centers the string argument in a string with the specified length. If the
  5136.  
  5137. length is longer than that of the string,pad characters or blanks are added as
  5138.  
  5139. necessary.
  5140.  
  5141. Examples:
  5142.  
  5143.         say center('abc',6)             ==>' abc '
  5144.  
  5145.         say center('abc',6,'+')         ==>'+abc++'
  5146.  
  5147.         say center('123456',3)          ==>'234'
  5148.  
  5149.  
  5150.  
  5151. CLOSE()
  5152.  
  5153. Usage:CLOSE(file)
  5154.  
  5155. Closes the file specified by the given logical name. The returned value is a
  5156.  
  5157. boolean success flag,and will be 1 unless the specified file was not open.
  5158.  
  5159. Example:
  5160.  
  5161.         say close('input')              ==>1
  5162.  
  5163.  
  5164.  
  5165. COMPRESS()
  5166.  
  5167. Usage:COMPRESS(string,[list])
  5168.  
  5169. If the list argument is omitted,the function removes leading,trailing,or
  5170.  
  5171. embedded blank characters from the string argument. If the optional list is
  5172.  
  5173. supplied,it specifies the characters to be removed from the string.
  5174.  
  5175. Examples:
  5176.  
  5177.         say compress (' why not ')      ==>whynot
  5178.  
  5179.         say compress ('++12-34-+','+-') ==>1234
  5180.  
  5181.  
  5182.  
  5183. COMPARE()
  5184.  
  5185. Usage:COMPARE(string1,string2,[pad])
  5186.  
  5187. Compares two strings and returns the index of the first position in which they
  5188.  
  5189. differ,or 0 if the strings are identical. The shorter string is padded as
  5190.  
  5191. required using the supplied character or blanks.
  5192.  
  5193. Examples:
  5194.  
  5195.         say compare('abcde','abcce')    ==>4
  5196.  
  5197.         say compare('abcde',abcde')     ==>0
  5198.  
  5199.         say compare('abc++','abc+-','+') ==>5
  5200.  
  5201.  
  5202.  
  5203. COPIES()
  5204.  
  5205. Usage:COPIES(string,number)
  5206.  
  5207. Creates a new string by concatenating the specified number of copies of the
  5208.  
  5209. original. The number argument may be zero,in which case the null string is
  5210.  
  5211. returned.
  5212.  
  5213.  
  5214.  
  5215.                                 55
  5216.  
  5217.  
  5218.  
  5219. Example:
  5220.  
  5221.         say copies('abc',3)             ==>abcabcabc
  5222.  
  5223.  
  5224.  
  5225. D2C()
  5226.  
  5227. Usage:D2C(number)
  5228.  
  5229. Creates a string whose value is the binary(packed)representation of the given
  5230.  
  5231. decimal number.
  5232.  
  5233. Example:
  5234.  
  5235.         d2c(31)                         ==>'1F'x
  5236.  
  5237.  
  5238.  
  5239. DATATYPE()
  5240.  
  5241. Usage:DATATYPE9string,[option])
  5242.  
  5243. If the option parameter is not specified,DATATYPE()tests whether the string
  5244.  
  5245. parameter is a valid number and returns either NUM or CHAR. If an option
  5246.  
  5247. keyword is given,the boolean return indicates whether the string satisfied the
  5248.  
  5249. requested test. The following option keywords are recognized:
  5250.  
  5251.  
  5252.  
  5253.                          DATATYPE()Options
  5254.  
  5255.  
  5256.  
  5257.         KEYWORD                 CHARACTERS ACCEPTED
  5258.  
  5259.         Alphanumeric            Alphabetics (A-Z,a-z)
  5260.  
  5261.                                 or Numerics (0-9)
  5262.  
  5263.         Binary                  Binary Digits String
  5264.  
  5265.         Lowercase               Lowercase Alphabetics (a-z)
  5266.  
  5267.         Mixed                   Mixed Upper/Lowercase
  5268.  
  5269.         Numeric                 Valid Numbers
  5270.  
  5271.         Symbol                  Valid REXX Symbols
  5272.  
  5273.         Upper                   Uppercase Alphabetics (A-Z)
  5274.  
  5275.         Whole                   Integer Numbers
  5276.  
  5277.         X                       Hex Digits String
  5278.  
  5279. Examples:
  5280.  
  5281.         say datatype('123')                     ==>NUM
  5282.  
  5283.         say datatype('1a f2','x')               ==>1
  5284.  
  5285.         say datatype('aBcde','L')               ==>0
  5286.  
  5287.  
  5288.  
  5289. DELSTR()
  5290.  
  5291. Usage:DELSTR(string,n,[length])
  5292.  
  5293. Deletes the substring of the string argument beginning with the nth character
  5294.  
  5295. for the specified length in characters. The default length is the remaining
  5296.  
  5297. length of the string.
  5298.  
  5299. Example:
  5300.  
  5301.         say delstr('123456',2,3)                ==>156
  5302.  
  5303.  
  5304.  
  5305.                                 56
  5306.  
  5307.  
  5308.  
  5309. DELWORD()
  5310.  
  5311. Usage:DELWORD(string,n,[length])
  5312.  
  5313. Deletes the substring of the string argument beginning with the nth word for
  5314.  
  5315. the specified length in words. The default length is the remaining length of
  5316.  
  5317. the string. The deleted string includes any trailing blanks following the last
  5318.  
  5319. word.
  5320.  
  5321. Examples:
  5322.  
  5323.         say delword('Tell me a story',2,2)==>'Tell story'
  5324.  
  5325.         say delword('one two three',3)    ==>'one two '
  5326.  
  5327.  
  5328.  
  5329. EOF()
  5330.  
  5331. Usage:EOF(file)
  5332.  
  5333. Checks the specified logical file name and returns the boolean value 1(True)if
  5334.  
  5335. the end-of-file has been reached,and 0(False)otherwise.
  5336.  
  5337. Example:
  5338.  
  5339.         say eof(infile)                 ==>1
  5340.  
  5341.  
  5342.  
  5343. ERRORTEXT()
  5344.  
  5345. Usage:ERRORTEXT(n)
  5346.  
  5347. Returns the error message associated with the specified ARexx code. The null
  5348.  
  5349. string is returned if the number is not a valid error code.
  5350.  
  5351. Example:
  5352.  
  5353.         say errortext(41)               ==>Invalid expression
  5354.  
  5355.  
  5356.  
  5357. EXISTS()
  5358.  
  5359. Usage:EXISTS(filename)
  5360.  
  5361. Tests whether an external file of the given filename exists. The name string
  5362.  
  5363. may include device and directory specifications.
  5364.  
  5365. Example:
  5366.  
  5367.         say exists('df0:c/ed')          ==>1
  5368.  
  5369.  
  5370.  
  5371. EXPORT()
  5372.  
  5373. Usage:EXPORT(address,[string],[length],[pad])
  5374.  
  5375. Copies data from the (optional) string into a previously-allocated memory area,
  5376.  
  5377. which must be specified as a 4-byte address. The length parameter specifies the
  5378.  
  5379. maximum number of characters to be copied; the default is the length of the
  5380.  
  5381. string. If the specified length is longer than the string,the remaining area is
  5382.  
  5383. filled with the pad character or nulls('00'x). The returned value is the number
  5384.  
  5385. of characters copied.
  5386.  
  5387.  
  5388.  
  5389. Caution is advised in using this function. Any area of memory can be
  5390.  
  5391. overwritten,possibly causing a system crash. Task switching is forbidden while
  5392.  
  5393. the copy is being done,so system performance may be degraded if long strings
  5394.  
  5395. are copied.
  5396.  
  5397. See Also:IMPORT(),STORAGE()
  5398.  
  5399.  
  5400.  
  5401.                                 57
  5402.  
  5403.  
  5404.  
  5405. Example:
  5406.  
  5407.         count = export('0004 0000'x,'The answer')
  5408.  
  5409.  
  5410.  
  5411. FREESPACE()
  5412.  
  5413. Usage:FREESPACE(address,length)
  5414.  
  5415. Returns a block of memory of the given length to the interpreter's internal
  5416.  
  5417. pool. The address argument must be a 4-byte string obtained by a prior call to
  5418.  
  5419. GETSPACE(),the internal allocator. It is not always necessary to release
  5420.  
  5421. internally-allocated memory,since it will be released to the system when the
  5422.  
  5423. program terminates. However,if a very large block has been allocated,returning
  5424.  
  5425. it to the pool may avoid memory space problems. The return value is a boolean
  5426.  
  5427. success flag.
  5428.  
  5429. See Also:GETSPACE()
  5430.  
  5431. Example:
  5432.  
  5433.         say freespace('00042000'x,32)           ==>1
  5434.  
  5435.  
  5436.  
  5437. GETCLIP()
  5438.  
  5439. Usage:GETCLIP(name)
  5440.  
  5441. Searches the Clip List for an entry matching the supplied name parameter,and
  5442.  
  5443. returns the associated value string. The name-matching is case-sensitive,and
  5444.  
  5445. the null string is returned if the name cannot be found. The usage and
  5446.  
  5447. maintenance of Clip List entries is described in the Chapter 9.
  5448.  
  5449. See Also:SETCLIP()
  5450.  
  5451. Example:
  5452.  
  5453.         /* Assume 'numbers' contains 'PI=3.14159'    */
  5454.  
  5455.         say getclip('numbers')          ==>PI=3.14159
  5456.  
  5457.  
  5458.  
  5459. GETSPACE()
  5460.  
  5461. Usage:GETSPACE(length)
  5462.  
  5463. Allocates a block of memory of the specified length from the interpreter's
  5464.  
  5465. internal pool. The returned value is the 4-byte address of the allocated block,
  5466.  
  5467. which is not cleared or otherwise initialized. Internal memory is automatically
  5468.  
  5469. returned to the system when the ARexx program terminates,so this function
  5470.  
  5471. should not be used to allocate memory for use by external programs. The Support
  5472.  
  5473. Library(described in Appendix D)includes the function ALLOCMEM()which to
  5474.  
  5475. allocate memory from the system free list.
  5476.  
  5477. See Also:FREESPACE()
  5478.  
  5479. Example:
  5480.  
  5481.         say c2x(getspace(32))           ==>'0003BF40'x
  5482.  
  5483.  
  5484.  
  5485. HASH()
  5486.  
  5487. Usage:HASH(string)
  5488.  
  5489. Returns the hash attribute of a string as a decimal number,and updates the
  5490.  
  5491. internal hash value of the string.
  5492.  
  5493.  
  5494.  
  5495.                                 58
  5496.  
  5497.  
  5498.  
  5499. Example:
  5500.  
  5501.         say hash('1')                   ==>49
  5502.  
  5503.  
  5504.  
  5505. IMPORT()
  5506.  
  5507. Usage:IMPORT(address,[length])
  5508.  
  5509. Creates a string by copying data from the specified 4-byte address. If the
  5510.  
  5511. length parameter is not supplied,the copy terminates when a null byte is found.
  5512.  
  5513. See Also:EXPORT()
  5514.  
  5515. Example:
  5516.  
  5517.         extval = import('0004 0000'x,8)
  5518.  
  5519.  
  5520.  
  5521. INDEX()
  5522.  
  5523. Usage:INDEX(string,pattern,[start])
  5524.  
  5525. Searches for the first occurrence of the pattern argument in the string
  5526.  
  5527. argument,beginning at the specified start position. The default start position
  5528.  
  5529. is 1. The returned value is the index of the matched pattern,or 0 if the
  5530.  
  5531. pattern was not found.
  5532.  
  5533. Examples:
  5534.  
  5535.         say index("123456","23")        ==>2
  5536.  
  5537.         say index("123456","77")        ==>0
  5538.  
  5539.         say index("123123","23",3)      ==>5
  5540.  
  5541.  
  5542.  
  5543. INSERT()
  5544.  
  5545. Usage:INSERT(new,old,[start],[length],[pad])
  5546.  
  5547. Inserts the new string into the old string after the specified start position.
  5548.  
  5549. The default starting position is 0. The new string is truncated or padded to
  5550.  
  5551. the specified length as required,using the supplied pad character or blanks. If
  5552.  
  5553. the start position is beyond the end of the old string,the old string is padded
  5554.  
  5555. on the right.
  5556.  
  5557. Examples:
  5558.  
  5559.         say insert('ab,'12345')         ==>ab12345
  5560.  
  5561.         say insert('123','++',3,5,'-')  ==>++-123--
  5562.  
  5563.  
  5564.  
  5565. LASTPOS()
  5566.  
  5567. Usage:LASTPOS(pattern,string,[start])
  5568.  
  5569. Searches backwards for the first occurrence of the pattern argument in the
  5570.  
  5571. string argument,beginning at the specified start position. The default starting
  5572.  
  5573. position is the end of the string. The returned value is the index of the
  5574.  
  5575. matched pattern,or 0 if the pattern was not found.
  5576.  
  5577.  
  5578.  
  5579.                                 59
  5580.  
  5581.  
  5582.  
  5583. Examples:
  5584.  
  5585.         say lastpos("123234","2")       ==>4
  5586.  
  5587.         say lastpos("123234","5")       ==>0
  5588.  
  5589.         say lastpos("123234","2",3)     ==>2
  5590.  
  5591.  
  5592.  
  5593. LEFT()
  5594.  
  5595. Usage:LEFT(string,length,[pad])
  5596.  
  5597. Returns the leftmost substring in the given string argument with the specified
  5598.  
  5599. length. If the substring is shorter than the requested length,it is padded on
  5600.  
  5601. the left with the supplied pad character or blanks.
  5602.  
  5603. Examples:
  5604.  
  5605.         say left('123456',3)            ==>123
  5606.  
  5607.         say left('123456',8,'+')        ==>123456++
  5608.  
  5609.  
  5610.  
  5611. LENGTH()
  5612.  
  5613. Usage:LENGTH(string)
  5614.  
  5615. Returns the length of the string.
  5616.  
  5617. Example:
  5618.  
  5619.         say length('three')             ==>5
  5620.  
  5621.  
  5622.  
  5623. MAX()
  5624.  
  5625. Usage:MAX(number,number[,number,...])
  5626.  
  5627. Returns the maximum of the supplied arguments,all of which must be numeric. At
  5628.  
  5629. least two parameters must be supplied.
  5630.  
  5631. Example:
  5632.  
  5633.         say max(2.1,3,-1_               ==>3
  5634.  
  5635.  
  5636.  
  5637. MIN()
  5638.  
  5639. Usage:MIN(number,number[,number,...])
  5640.  
  5641. Returns the minimum of the supplied arguments,all of which must be numeric. At
  5642.  
  5643. least two parameters must be supplied.
  5644.  
  5645. Example:
  5646.  
  5647.         say min(2.1,3,-1)               ==>-1
  5648.  
  5649.  
  5650.  
  5651. OPEN()
  5652.  
  5653. Usage:OPEN(file,filename,['Append' | 'Read' | 'Write'])
  5654.  
  5655. Opens an external file for the specified operation. The file argument defines
  5656.  
  5657. the logical name by which the file will be referenced. The filename is the
  5658.  
  5659. external name of the file,and may include device and directory specifications.
  5660.  
  5661. The function returns a boolean value that indicates whether the operation was
  5662.  
  5663. successful. There is no limit to the number of files that can be open
  5664.  
  5665.  
  5666.  
  5667.                                 60
  5668.  
  5669.  
  5670.  
  5671. simultaneusly,and all open files are closed automatically when the program
  5672.  
  5673. exits.
  5674.  
  5675. See Also:CLOSE(),READ(),WRITE()
  5676.  
  5677. Examples:
  5678.  
  5679.         say open('MyCon','CON:160/50/320/100/MyCon/cds') ==>1
  5680.  
  5681.         say open('outfile','ram:temp','W')               ==>1
  5682.  
  5683.  
  5684.  
  5685. OVERLAY()
  5686.  
  5687. Usage:OVERLAY(new,old,[start],[length],[pad])
  5688.  
  5689. Overlays the new string onto the old string beginning at the specified start
  5690.  
  5691. position,which must be positive. The default starting position is 1. The new
  5692.  
  5693. string is truncated or padded to the specified length as required,using the
  5694.  
  5695. supplied pad character or blanks. If the start position is beyond the end of
  5696.  
  5697. the old string,the old string is padded on the right.
  5698.  
  5699. Examples:
  5700.  
  5701.         say overlay('bb,'abcd')                 ==>bbcd
  5702.  
  5703.         say overlay('4','123',5,5,'-')          ==>123--4----
  5704.  
  5705.  
  5706.  
  5707. POS()
  5708.  
  5709. Usage:POS(pattern,string,[start])
  5710.  
  5711. Searches for the first occurrence of the pattern argument in the string
  5712.  
  5713. argument,beginning at the position specified by the start argument. The default
  5714.  
  5715. starting position is 1. The returned value is the index of the matched
  5716.  
  5717. string,or 0 if the pattern wasn't found.
  5718.  
  5719. Examples:
  5720.  
  5721.         say pos('23','123234')                  ==>2
  5722.  
  5723.         say pos('77','123234')                  ==>0
  5724.  
  5725.         say pos('23','123234',3)                ==>4
  5726.  
  5727.  
  5728.  
  5729. PRAGMA()
  5730.  
  5731. Usage:PRAGMA(option,[value])
  5732.  
  5733. This function allows a program to change various attributes relating to the
  5734.  
  5735. system environment within which the program executes. The option argument is a
  5736.  
  5737. keyword that specifies an environmental attribute;the currently implemented
  5738.  
  5739. options are Directory and Priority. The value argument supplies the new
  5740.  
  5741. attribute value to be installed. The value returned by the function depends on
  5742.  
  5743. the attribute selected. Some attributes return the previous value
  5744.  
  5745. installed,while others may simply set a boolean success flag. The currently
  5746.  
  5747. defined option keywords are listed below.
  5748.  
  5749.  
  5750.  
  5751. DIRECTORY. Specifies a new "current" directory. The current directory is used
  5752.  
  5753. as the "root" for filenames that do not explicitly include a device
  5754.  
  5755. specification. The return value is a boolean success flag.
  5756.  
  5757.  
  5758.  
  5759. PRIORITY. Specifies a new task priority. The priority value must be an integer
  5760.  
  5761. in the range -128 to 127,but the practical range is much more limited. ARexx
  5762.  
  5763. programs should never be run at a priority higher than that of the resident
  5764.  
  5765. process,which currently runs at priority 4. The returned value is the previous
  5766.  
  5767. priority level.
  5768.  
  5769.  
  5770.  
  5771.                                 61
  5772.  
  5773.  
  5774.  
  5775. Examples:
  5776.  
  5777.         say pragma('priority',-5)               ==>0
  5778.  
  5779.         call pragma 'Directory','df0:system'
  5780.  
  5781.  
  5782.  
  5783. RANDOM()
  5784.  
  5785. Usage:RANDOM([min],[max],[seed])
  5786.  
  5787. Returns a pseudorandom integer in the interval specified by the min and max
  5788.  
  5789. arguments. The default minimum value is 0 and the default maximum value is 999.
  5790.  
  5791. The interval max-min must be less than or equal to 1000. If a greater range of
  5792.  
  5793. random integers is required,the values from the RANDU()function can be suitable
  5794.  
  5795. scaled and translated.
  5796.  
  5797.  
  5798.  
  5799. The seed argument can be supplied to initialize the internal state of the
  5800.  
  5801. random number generator.
  5802.  
  5803. See Also:RANDU()
  5804.  
  5805. Example:
  5806.  
  5807.         thisroll = random(1,6)  /* might be 1   */
  5808.  
  5809.         nextroll = random(1,6)  /* snake eyes?  */
  5810.  
  5811.  
  5812.  
  5813. RANDU()
  5814.  
  5815. Usage:RANDU([seed])
  5816.  
  5817. Returns a uniformly-distributed pseudorandom number between 0 and 1. The number
  5818.  
  5819. of digits of precision in the result is always equal to the current Numeric
  5820.  
  5821. Digits setting. With the choice of suitable scaling and translation values,
  5822.  
  5823. RANDU()can be used to generate pseudorandom numbers on an arbitrary interval.
  5824.  
  5825.  
  5826.  
  5827. The optional seed argument is used to initialize the internal state of the
  5828.  
  5829. random number generator.
  5830.  
  5831. See Also:RANDOM()
  5832.  
  5833. Example:
  5834.  
  5835.         firsttry = randu()      /* 0.371902021? */
  5836.  
  5837.         numeric digits 3
  5838.  
  5839.         tryagain = randu()      /* 0.873?       */
  5840.  
  5841.  
  5842.  
  5843. READCH()
  5844.  
  5845. Usage:READCH(file,length)
  5846.  
  5847. Reads the specified number of characters from the given logical file into a
  5848.  
  5849. string. The length of the returned string is the actual number of characters
  5850.  
  5851. read,and may be less than the requested length if,for example,the end-of-file
  5852.  
  5853. was reached.
  5854.  
  5855. See Also:READLN()
  5856.  
  5857. Example:
  5858.  
  5859.         instring = readch('input',10)
  5860.  
  5861.  
  5862.  
  5863.                                 62
  5864.  
  5865.  
  5866.  
  5867. READLN()
  5868.  
  5869. Usage:READLN(file)
  5870.  
  5871. Reads characters from the given logical file into a string until a "newline"
  5872.  
  5873. character is found. The returned string does not include the "newline".
  5874.  
  5875. See Also:READCH()
  5876.  
  5877. Examples:
  5878.  
  5879.         instring = readln('MyFile')
  5880.  
  5881.  
  5882.  
  5883. REMLIB()
  5884.  
  5885. Usage:REMLIB(name)
  5886.  
  5887. Removes an entry with the given name from the Library List maintained by the
  5888.  
  5889. resident process. The boolean return is 1 if the entry was found and
  5890.  
  5891. successfully removed. Note that this function does not make a distinction
  5892.  
  5893. between function libraries and function hosts,but simply removes a named entry.
  5894.  
  5895. See Also:ADDLIB()
  5896.  
  5897. Example:
  5898.  
  5899.         say remlib('MyLibrary.library')==>1
  5900.  
  5901.  
  5902.  
  5903. REVERSE()
  5904.  
  5905. Usage:REVERSE(string)
  5906.  
  5907. Reverses the sequence of characters in the string.
  5908.  
  5909. Example:
  5910.  
  5911.         say reverse('?ton yhw')         ==>why not?
  5912.  
  5913.  
  5914.  
  5915. RIGHT()
  5916.  
  5917. Usage:RIGHT(string,length,[pad])
  5918.  
  5919. Returns the rightmost substring in the given string argument with the specified
  5920.  
  5921. length. If the substring is shorter than the requested length,it is padded on
  5922.  
  5923. the left with the supplied pad character or blanks.
  5924.  
  5925. Examples:
  5926.  
  5927.         say right('123456',4)           ==>3456
  5928.  
  5929.         say right('123456',8,'+')       ==>++123456
  5930.  
  5931.  
  5932.  
  5933. SEEK()
  5934.  
  5935. Usage:SEEK(file,offset,['Begin' | 'Current' | 'End'])
  5936.  
  5937. Moves to a new position in the given logical file,specified as an offset from
  5938.  
  5939. an anchor position. The default anchor is Current. The returned value is the
  5940.  
  5941. new position relative to the start of the file.
  5942.  
  5943. Examples:
  5944.  
  5945.         say seek('input',10,'B')        ==>10
  5946.  
  5947.         say seek('input',O,'E')         ==>356  /* file length  */
  5948.  
  5949.  
  5950.  
  5951.                                 63
  5952.  
  5953.  
  5954.  
  5955. SETCLIP()
  5956.  
  5957. Usage:SETCLIP(name,[value])
  5958.  
  5959. Adds a name-value pair to the Clip List maintained by the resident process. If
  5960.  
  5961. an entry of the same name already exists,its value is updated to the supplied
  5962.  
  5963. value string. Entries may be removed by specifying a null value. The function
  5964.  
  5965. returns a boolean value that indicates whether the operation was successful.
  5966.  
  5967. Examples:
  5968.  
  5969.         say setclip('path','df0:s')     ==>1
  5970.  
  5971.         say setclip('path')             ==>1
  5972.  
  5973.  
  5974.  
  5975. SHOW()
  5976.  
  5977. Usage:SHOW(option,[name],[pad])
  5978.  
  5979. Returns the names in the resource list specified by the option argument,or
  5980.  
  5981. tests to see whether an entry with the specified name is available. The
  5982.  
  5983. currently implemented options keywords are Clip,Files,Libraries,and Ports,
  5984.  
  5985. which are described below.
  5986.  
  5987.  
  5988.  
  5989. Clip. Examines the names in the Clip List.
  5990.  
  5991. Files. Examines the names of the currently open logical file names.
  5992.  
  5993. Libraries. Examines the names in the Library List,which are either function
  5994.  
  5995. libraries or function hosts.
  5996.  
  5997. Ports. Examine the names in the system Ports List.
  5998.  
  5999.  
  6000.  
  6001. If the name argument is omitted,the function returns a string with the resource
  6002.  
  6003. names separated by a blank space or the pad character,if one was supplied. If
  6004.  
  6005. the name argument is given,the returned boolean value indicates whether the
  6006.  
  6007. name was found in the resource list. The name entries are case-sensitive.
  6008.  
  6009.  
  6010.  
  6011. SIGN()
  6012.  
  6013. Usage:SIGN(number)
  6014.  
  6015. Returns 1 if the number argument is positive or zero,and -1 if number is
  6016.  
  6017. negative. The argument must be numeric.
  6018.  
  6019. Examples:
  6020.  
  6021.         say sign(12)                    ==>1
  6022.  
  6023.         say sign(-33)                   ==>-1
  6024.  
  6025.  
  6026.  
  6027. SPACE()
  6028.  
  6029. Usage:SPACE(string,n,[pad])
  6030.  
  6031. Reformats the string argument so that there are n spaces(blank characters)
  6032.  
  6033. between each pair of words. If the pad character is specified,it is used
  6034.  
  6035. instead of blanks as the separator character. Specifying n as 0 will remove all
  6036.  
  6037. blanks from the string.
  6038.  
  6039. Examples:
  6040.  
  6041.         say space('Now is the time',3)  ==>'Now   is   the   time'
  6042.  
  6043.         say space('Now is the time',0)  ==>'Nowisthetime'
  6044.  
  6045.         say space('1 2 3',1,'+')        ==>'1+2+3'
  6046.  
  6047.  
  6048.  
  6049.                                 64
  6050.  
  6051.  
  6052.  
  6053. STORAGE()
  6054.  
  6055. Usage:STORAGE([address],[string],[length],[pad])
  6056.  
  6057. Calling STORAGE()with no arguments returns the available system memory. If the
  6058.  
  6059. address argument is given,it must be a 4-byte string,and the function copies
  6060.  
  6061. data from the(optional)string into the indicated memory area. The length
  6062.  
  6063. parameter specifies the maximum number of bytes to be copied,and defaults to
  6064.  
  6065. the length of the string. If the specified length is longer than the string,the
  6066.  
  6067. remaining area is filled with the pad character or nulls('00'x.)
  6068.  
  6069.  
  6070.  
  6071. The returned value is the previous contents of the memory area. This can be
  6072.  
  6073. used in a subsequent call to restore the original contents.
  6074.  
  6075.  
  6076.  
  6077. Caution is advised in using this function. Any area of memory can be
  6078.  
  6079. overwritten,possibly causing a system crash. Task switching is forbidden while
  6080.  
  6081. the copy is being done,so system performance may be degraded if long strings
  6082.  
  6083. are copied.
  6084.  
  6085. See Also:EXPORT()
  6086.  
  6087. Examples:
  6088.  
  6089.         say storage()                   ==>248400
  6090.  
  6091.         oldval = storage('0004 000'x,'The answer')
  6092.  
  6093.         call storage '0004 0000'x,,32,'+'
  6094.  
  6095.  
  6096.  
  6097. STRIP()
  6098.  
  6099. Usage:STRIP(string,[{'B' | 'L' | 'T'}],[pad])
  6100.  
  6101. If neither of the optional parameters is supplied,the function removes both
  6102.  
  6103. leading and trailing blanks from the string argument. The second argument
  6104.  
  6105. specifies whether Leading,Trailing,or Both(leading and trailing)characters are
  6106.  
  6107. to be removed. The optional pad(or unpad,perhaps)argument selects the character
  6108.  
  6109. to be removed.
  6110.  
  6111. Examples:
  6112.  
  6113.         say strip(' say what? ')                ==>'say what?'
  6114.  
  6115.         say strip(' say what? ','L')            ==>'say what? '
  6116.  
  6117.         say strip('++123+++','B','+')           ==>'123'
  6118.  
  6119.  
  6120.  
  6121. SUBSTR()
  6122.  
  6123. Usage:SUBSTR(string,start,[length],[pad])
  6124.  
  6125. Returns the substring of the string argument beginning at the specified start
  6126.  
  6127. position for the specified length. The starting position must be positive,and
  6128.  
  6129. the default length is the remaining length of the string. If the substring is
  6130.  
  6131. shorter than the requested length,it is padded on the left with the blanks or
  6132.  
  6133. the specified pad character.
  6134.  
  6135. Examples:
  6136.  
  6137.         say substr('23456',4,2)         ==>45
  6138.  
  6139.         say substr('myname',3,6,'=')    ==>name==
  6140.  
  6141.  
  6142.  
  6143.                                 65
  6144.  
  6145.  
  6146.  
  6147. SUBWORD()
  6148.  
  6149. Usage:SUBWORD(string,n,[length])
  6150.  
  6151. Returns the substring of the string argument beginning with the nth word for
  6152.  
  6153. the specified length in words. The default length is the remaining length of
  6154.  
  6155. the string. The returned string will never have leading or trailing blanks.
  6156.  
  6157. Example:
  6158.  
  6159.         say subword('Now is the time ',2,2)     ==>is the
  6160.  
  6161.  
  6162.  
  6163. SYMBOL()
  6164.  
  6165. Usage:SYMBOL(name)
  6166.  
  6167. Tests whether the name argument is a valid REXX symbol. If the name is not a
  6168.  
  6169. valid symbol,the function returns the string BAD. Otherwise,the returned string
  6170.  
  6171. is LIT if the symbol is uninitialized and VAR if it has been assigned a value.
  6172.  
  6173. Examples:
  6174.  
  6175.         say symbol('J')                 ==>VAR
  6176.  
  6177.         say symbol('x')                 ==>LIT
  6178.  
  6179.         say symbol('++')                -->BAD
  6180.  
  6181.  
  6182.  
  6183. TIME()
  6184.  
  6185. Usage:TIME(option)
  6186.  
  6187. Returns the current system time or controls the internal elapsed time counter.
  6188.  
  6189. The valid option keywords are listed below.
  6190.  
  6191.  
  6192.  
  6193.                          TIME()Options
  6194.  
  6195.  
  6196.  
  6197.         OPTION KEYWORD          DESCRIPTION
  6198.  
  6199.         Elapsed                 Elapsed time in seconds.
  6200.  
  6201.         Hours                   Current time in hours since midnight
  6202.  
  6203.         Minutes                 Current time in minutes since midnight
  6204.  
  6205.         Reset                   Reset the elapsed time clock
  6206.  
  6207.         Seconds                 Current time in seconds since midnight
  6208.  
  6209.  
  6210.  
  6211. If no option is specified,the function returns the current system time in the
  6212.  
  6213. form HH:MM:SS.
  6214.  
  6215. Examples:
  6216.  
  6217.         /* Suppose that the time is 1:02 AM ...         */
  6218.  
  6219.         say time('Hours')               ==>1
  6220.  
  6221.         say time('m')                   ==>62
  6222.  
  6223.         say time('S')                   ==>3720
  6224.  
  6225.         call time 'R'                   /* reset timer  */
  6226.  
  6227.         say time('E')                   ==>.020
  6228.  
  6229.  
  6230.  
  6231.                                 66
  6232.  
  6233.  
  6234.  
  6235. TRACE()
  6236.  
  6237. Usage:TRACE(option)
  6238.  
  6239. Sets the tracing mode to that specified by the option keyword,which must be one
  6240.  
  6241. of the valid alphabetic or prefix options. The tracing options are described in
  6242.  
  6243. Chapter 7. The TRACE()function will alter the tracing mode even during
  6244.  
  6245. interactive tracing,when TRACE instructions in the source program are ignored.
  6246.  
  6247. The returned value is the mode in effect before the function call;this allows
  6248.  
  6249. the previous trace mode to be restored later.
  6250.  
  6251. Example:
  6252.  
  6253.         /* Assume tracing mode is ?AL           */
  6254.  
  6255.         say trace('Results')            ==>?A
  6256.  
  6257.  
  6258.  
  6259. TRANSLATE()
  6260.  
  6261. Usage:TRANSLATE(string,[output],[input],[pad])
  6262.  
  6263. This function constructs a translation table and uses it to replace selected
  6264.  
  6265. characters in the argument string. If only the string argument is given,it is
  6266.  
  6267. translated to uppercase. If an input table is supplied,it modifies the
  6268.  
  6269. translation table so that characters in the argument string that occur in the
  6270.  
  6271. input table are replaced with the corresponding character in the output table.
  6272.  
  6273. Characters beyond the end of the output table are replaced with the specified
  6274.  
  6275. pad character or a blank.
  6276.  
  6277.  
  6278.  
  6279. Note that the result string is always of the same length as the original
  6280.  
  6281. string. The input and output tables may be of any length.
  6282.  
  6283. Examples:
  6284.  
  6285.         say translate("abcde","123","cbade","+")        ==>321++
  6286.  
  6287.         say translate("low")                            ==>LOW
  6288.  
  6289.         say translate("0110","10","01")                 ==>1001
  6290.  
  6291.  
  6292.  
  6293. TRIM()
  6294.  
  6295. Usage:TRIM(string)
  6296.  
  6297. Removes trailing blanks from the string argument.
  6298.  
  6299. Example:
  6300.  
  6301.         say length(trim(' abc  '))      ==>4
  6302.  
  6303.  
  6304.  
  6305. UPPER()
  6306.  
  6307. Usage:UPPER(string)
  6308.  
  6309. Translates the strip to uppercase. The action of this function is equivalent to
  6310.  
  6311. that of TRANSLATE(string),but it is slightly faster for short strings.
  6312.  
  6313. Example:
  6314.  
  6315.         say upper('One Fine Day')       ==>ONE FINE DAY
  6316.  
  6317.  
  6318.  
  6319.                                 67
  6320.  
  6321.  
  6322.  
  6323. VALUE()
  6324.  
  6325. Usage:VALUE(name)
  6326.  
  6327. Returns the value of the symbol represented by the name argument.
  6328.  
  6329. Example:
  6330.  
  6331.         /* Assume that J has the value of 12            */
  6332.  
  6333.         say value('j')                  ==>12
  6334.  
  6335.  
  6336.  
  6337. VERIFY()
  6338.  
  6339. Usage:VERIFY(string,list,['Match'])
  6340.  
  6341. If the Match argument is omitted,the function returns the index of the first
  6342.  
  6343. character in the string argument which is not contained in the list argument,or
  6344.  
  6345. 0 if all of the characters are in the list. If the Match keyword is supplied,
  6346.  
  6347. the function returns the index of the first character which is in the list,or 0
  6348.  
  6349. if none of the characters are.
  6350.  
  6351. Examples:
  6352.  
  6353.         say verify('123456','0123456789')       ==>0
  6354.  
  6355.         say verify('123a56','0123456789')       ==>4
  6356.  
  6357.         say verify('123a45','abcdefghij','m')   ==>4
  6358.  
  6359.  
  6360.  
  6361. WORD()
  6362.  
  6363. Usage:WORD(string,n)
  6364.  
  6365. Returns the nth word in the string argument,or the null string if there are
  6366.  
  6367. fewer than n words.
  6368.  
  6369. Example:
  6370.  
  6371.         say word('Now is the time ',2)          ==>is
  6372.  
  6373.  
  6374.  
  6375. WORDINDEX()
  6376.  
  6377. Usage:WORINDEX(string,n)
  6378.  
  6379. Returns the starting position of the nth word in the argument string,or 0 if
  6380.  
  6381. there are fewer than n words.
  6382.  
  6383. Example:
  6384.  
  6385.         say wordindex('Now is the time ',3)     ==>8
  6386.  
  6387.  
  6388.  
  6389. WORDLENGTH()
  6390.  
  6391. Usage:WORDLENGTH(string,n)
  6392.  
  6393. Returns the length of the nth word in the string argument.
  6394.  
  6395. Example:
  6396.  
  6397.         say wordlength('one two three',3)       ==>5
  6398.  
  6399.  
  6400.  
  6401.                                 68
  6402.  
  6403.  
  6404.  
  6405. WORDS()
  6406.  
  6407. Usage:WORDS(string)
  6408.  
  6409. Returns the number of words in the string argument.
  6410.  
  6411. Example:
  6412.  
  6413.         say words("You don't say!")             ==>3
  6414.  
  6415.  
  6416.  
  6417. WRITECH()
  6418.  
  6419. Usage:WRITECH(file,string)
  6420.  
  6421. Writes the string argument to the given logical file. The returned value is the
  6422.  
  6423. actual number of characters written.
  6424.  
  6425. Example:
  6426.  
  6427.         say writech('output','Testing')         ==>7
  6428.  
  6429.  
  6430.  
  6431. WRITELN()
  6432.  
  6433. Usage:WRITELN(file,string)
  6434.  
  6435. Writes the string argument to the given logical file with a "newline" appended.
  6436.  
  6437. The returned value is the actual number of characters written.
  6438.  
  6439. Example:
  6440.  
  6441.         say writeln('output','Testing')         ==>8
  6442.  
  6443.  
  6444.  
  6445. X2C()
  6446.  
  6447. Usage:X2C(string)
  6448.  
  6449. Converts a string of hex digits into the(packed)character representation. Blank
  6450.  
  6451. characters are permitted in the argument string at byte boundaries.
  6452.  
  6453. Examples:
  6454.  
  6455.         say x2c('12ab')                         ==>'12ab'x
  6456.  
  6457.         say x2c('12 ab')                        ==>'12ab'x
  6458.  
  6459.  
  6460.  
  6461. XRANGE()
  6462.  
  6463. Usage:XRANGE([start],[end])
  6464.  
  6465. Generates a string consisting of all characters numerically between the
  6466.  
  6467. specified start and end values. The default start character is '00'x,and the
  6468.  
  6469. default end character is 'FF'x. Only the first character of the start and end
  6470.  
  6471. arguments is significant.
  6472.  
  6473. Examples:
  6474.  
  6475.         say xrange()                    ==>'00010203 ... FDFEFF'x
  6476.  
  6477.         say xrange('a','f')             ==>'abcdef'
  6478.  
  6479.         say xrange(,'10'x)              ==>'00010203040506070809010'x
  6480.  
  6481.  
  6482.  
  6483.                                 69
  6484.  
  6485.  
  6486.  
  6487.                         CHAPTER 7 TRACING AND INTERRUPTS
  6488.  
  6489.  
  6490.  
  6491. ARexx provides tracing and source-level debugging facilities that are unusual
  6492.  
  6493. in a high-level language. Tracing refers to the ability to display selected
  6494.  
  6495. statements in a program as the program executes. When a clause is traced,its
  6496.  
  6497. line number,source text,and related information are displayed on the console.
  6498.  
  6499. The tracing action of the interpreter is determined by a trace option that
  6500.  
  6501. selects which source clauses will be traced,and two modifier flags that control
  6502.  
  6503. command inhibition and interactive tracing.
  6504.  
  6505.  
  6506.  
  6507. The internal interrupt system enables an ARexx program to detect certain
  6508.  
  6509. synchronous or asynchronous events and to take special actions when they occur.
  6510.  
  6511. Events such as a syntax error or an external halt request that would normally
  6512.  
  6513. cause the program to exit can instead be trapped so that corrective actions can
  6514.  
  6515. be taken.
  6516.  
  6517.  
  6518.  
  6519. TRACING OPTIONS
  6520.  
  6521.  
  6522.  
  6523. Trace options are sometimes called an alphabetic options,since the keywords
  6524.  
  6525. that select an option can be shortened to one letter for convenience. The
  6526.  
  6527. alphabetic options are:
  6528.  
  6529.  
  6530.  
  6531. ALL. All clauses are traced.
  6532.  
  6533. COMMANDS. All command clauses are traced before being sent to the external
  6534.  
  6535. host. Non-zero return codes are displayed on the console.
  6536.  
  6537. ERRORS. Commands that generate a non-zero return code are traced after the
  6538.  
  6539. clause is executed.
  6540.  
  6541. INTERMEDIATES. All clauses are traced,and intermediate results are displayed
  6542.  
  6543. during expression evaluation. These include the values retrieved for variables,
  6544.  
  6545. expanded compound names,and the results of function calls.
  6546.  
  6547. LABELS. All label clauses are traced as they are executed. A label will be
  6548.  
  6549. displayed each time a transfer of control takes place.
  6550.  
  6551. NORMAL. Command clauses will return codes that exceed the current error failure
  6552.  
  6553. level are traced after execution,and an error message is displayed. This is the
  6554.  
  6555. default trace option.
  6556.  
  6557. RESULTS. All clauses are traced before execution,and the final result of each
  6558.  
  6559. expression is displayed. Values assigned to variables by ARG,PARSE,or PULL
  6560.  
  6561. instructions are also displayed.
  6562.  
  6563. SCAN. This is a special option that traces all clauses and checks for errors,
  6564.  
  6565. but suppresses the actual execution of the statements. It is helpful as a
  6566.  
  6567. preliminary screening steop for a newly-created program.
  6568.  
  6569.  
  6570.  
  6571. The tracing mode can be set using either the TRACE instruction or the TRACE()
  6572.  
  6573. Built-In function. The RESULTS trace option is recommended for general-purpose
  6574.  
  6575. testing. Tracing can be selectively disabled from within a program so that
  6576.  
  6577. previously-tested parts of a program can be skipped.
  6578.  
  6579.  
  6580.  
  6581.                                 71
  6582.  
  6583.  
  6584.  
  6585. DISPLAY FORMATTING
  6586.  
  6587.  
  6588.  
  6589. Each trace line displayed on the console is indented to show the effective
  6590.  
  6591. control(nesting)level at that clause,and is identified by a special three-
  6592.  
  6593. character code,as shown in Table 7.1 below. The source for each clause is
  6594.  
  6595. preceded by its line number in the program. Expression results or intermediates
  6596.  
  6597. are enclosed in double quotes so that leading and trailing blanks will be
  6598.  
  6599. apparent.
  6600.  
  6601.  
  6602.  
  6603.                          TRACING PREFIX CODES
  6604.  
  6605.  
  6606.  
  6607.                 CODE            DISPLAYED VALUES
  6608.  
  6609.                 +++             Command or syntax error
  6610.  
  6611.                 >C>             Expanded compound name
  6612.  
  6613.                 >F>             Result of a function call
  6614.  
  6615.                 >L>             Label clause
  6616.  
  6617.                 >O>             Result of a dyadic operation
  6618.  
  6619.                 >P>             Result of a prefix operation
  6620.  
  6621.                 >U>             Uninitialized variable
  6622.  
  6623.                 >V>             Value of a variable
  6624.  
  6625.                 >>>             Expression or template result
  6626.  
  6627.                 >.>             "Placeholder" token value
  6628.  
  6629.  
  6630.  
  6631. TRACING OUTPUT
  6632.  
  6633.  
  6634.  
  6635. The tracing output from a program is always directed to one of two logical
  6636.  
  6637. streams. The interpreter first checks for a stream named STDERR,and directs the
  6638.  
  6639. output there if the steam exists. Otherwise the trace output goes to the
  6640.  
  6641. standard output stream STDOUT and will be interleaved with the normal console
  6642.  
  6643. output of the program. The STDERR and STDOUT streams can be opened and closed
  6644.  
  6645. under program control,so the programmer has complete control over the
  6646.  
  6647. destination of tracing output.
  6648.  
  6649.  
  6650.  
  6651. In some cases a program may not have a predefined output stream. For example,a
  6652.  
  6653. program invoked from a host application that did not provide input and output
  6654.  
  6655. streams would not have an output console. To provide a tracing facility for
  6656.  
  6657. such programs,the resident process can open a special global tracing console
  6658.  
  6659. for use by any active program. When this console opens,the interpreter
  6660.  
  6661. automatically opens a stream named STDERR for each ARexx program in which
  6662.  
  6663. STDERR is not currently defined,and the program then diverts its tracing output
  6664.  
  6665. to the new stream.
  6666.  
  6667.  
  6668.  
  6669. The global console can be opened and closed using the command utilities too and
  6670.  
  6671. tcc,respectively. The console may not close immediately upon request,however.
  6672.  
  6673. The resident process waits until all active programs have diverted their
  6674.  
  6675. tracing streams back to the default state before actually closing the console.
  6676.  
  6677. Applications programs may provide direct control over the tracing console by
  6678.  
  6679. sending request packets to the resident process,which is discussed in Chapter
  6680.  
  6681. 10.
  6682.  
  6683.  
  6684.  
  6685. The trace stream(STDERR or STDOUT)is also used for trace input,so a program in
  6686.  
  6687. interactive tracing mode will wait for user input from this console. The global
  6688.  
  6689. tracing console is always shared among all currently active programs. Since it
  6690.  
  6691. may be confusing to have several programs simultaneously writing to the same
  6692.  
  6693. console,it is recommended that only one program at a time be traced using the
  6694.  
  6695. global console.
  6696.  
  6697.  
  6698.  
  6699.                                 72
  6700.  
  6701.  
  6702.  
  6703. COMMAND INHIBITION
  6704.  
  6705.  
  6706.  
  6707. ARexx provides a tracing mode called command inhibition that suppresses host
  6708.  
  6709. commands. In this mode command clauses are evaluated in the normal manner,but
  6710.  
  6711. the command is not actually sent to the external host,and the return code is
  6712.  
  6713. set to zero. This provides a way to test programs that issue potentially
  6714.  
  6715. destructive commands,such as erasing files or formatting disks. Command
  6716.  
  6717. inhibition does not apply to command clauses that are entered interactively.
  6718.  
  6719. These commands are always performed,but the value of the special variable RC is
  6720.  
  6721. left unchanged.
  6722.  
  6723.  
  6724.  
  6725. Command inhibition may be used in conjunction with any trace option. It is
  6726.  
  6727. controlled by the "!" character,which may appear by itself or may precede any
  6728.  
  6729. of the alphabetic options in a TRACE instruction. Each occurrence of the "!"
  6730.  
  6731. character "toggles" the inhibition mode currently in effect. Command inhibition
  6732.  
  6733. is cleared when tracing is set to OFF.
  6734.  
  6735.  
  6736.  
  6737. INTERACTIVE TRACING
  6738.  
  6739.  
  6740.  
  6741. Interactive tracing is a debugging facility that allows the user to enter
  6742.  
  6743. source statements while a program is executing. These statements may be used to
  6744.  
  6745. examine or modify variable values,issue commands,or otherwise interact with the
  6746.  
  6747. program. Any valid language statements can be entered interactively,with the
  6748.  
  6749. same rules and restrictions that apply to the INTERPRET instruction. In
  6750.  
  6751. particular,compound statements such as DO and SELECT must be complete within
  6752.  
  6753. the entered line.
  6754.  
  6755.  
  6756.  
  6757. Interactive tracing can be used with any of the trace options. While in
  6758.  
  6759. interactive tracing mode,the interpreter pauses after each traced clause and
  6760.  
  6761. prompts for input with the code "+++." At each pause,three types of user
  6762.  
  6763. responses are possible.
  6764.  
  6765.  
  6766.  
  6767.         If a null line is entered,the program continues to the next pause
  6768.  
  6769.         point.
  6770.  
  6771.         If an "=" character is entered,the preceding clause is executed again.
  6772.  
  6773.         Any other input is treated as a debugging statement,and is scanned and
  6774.  
  6775.         executed.
  6776.  
  6777.  
  6778.  
  6779. The pause points during interactive tracing are determined by the tracing
  6780.  
  6781. option currently in effect,as the interpreter pauses only after a traced
  6782.  
  6783. clause. However,certain instructions cannot be safely(or sensibly)re-executed,
  6784.  
  6785. so the interpreter will not pause after executing one of these. The "no-pause"
  6786.  
  6787. instructions are CALL,DO,ELSE,IF,THEN,and OTHERWISE. The interpreter will also
  6788.  
  6789. not pause after any clause that generate and execution error.
  6790.  
  6791.  
  6792.  
  6793. Interactive tracing mode is controlled by the "?" character,either by itself or
  6794.  
  6795. in combination with an alphabetic trace option. Any number of "?" characters
  6796.  
  6797. may precede an option,and each occurrence toggles the mode currently in effect.
  6798.  
  6799. For example,if the current trace option was NORMAL,then "TRACE ?R" would set
  6800.  
  6801. the option to RESULTS and select interactive tracing mode. A subsequent "TRACE
  6802.  
  6803. ?" would turn off interactive tracing.
  6804.  
  6805.  
  6806.  
  6807.                                 73
  6808.  
  6809.  
  6810.  
  6811. ERROR PROCESSING
  6812.  
  6813.  
  6814.  
  6815. The ARexx interpreter provides special error processing while it executes
  6816.  
  6817. debugging statements. Errors that occur during interactive debugging are
  6818.  
  6819. reported,but do not cause the program to terminate. This special processing
  6820.  
  6821. applies only to the statements that were entered interactively. Errors occuring
  6822.  
  6823. in the program source statements are treated in the usual way whether or not
  6824.  
  6825. the interpreter is in interactive tracing mode.
  6826.  
  6827.  
  6828.  
  6829. In addition to the special error processing,the interpreter also disables the
  6830.  
  6831. internal interrupt flags during interactive debugging. This is necessary to
  6832.  
  6833. prevent an accidental transfer of control due to an error or uninitialized
  6834.  
  6835. variable. However,if a "SIGNAL label" instruction is entered,the transfer will
  6836.  
  6837. take place,and any remaining interactive input will be abandoned. The SIGNAL
  6838.  
  6839. instruction can still be used to alter the interrupt flags,and the new settings
  6840.  
  6841. will take effect when the interpreter returns to normal processing.
  6842.  
  6843.  
  6844.  
  6845. THE EXTERNAL TRACING FLAG
  6846.  
  6847.  
  6848.  
  6849. The ARexx resident process maintains an external tracing flag that can be used
  6850.  
  6851. to force programs into interactive tracing mode. The tracing flag can be set
  6852.  
  6853. using the ts command utility. When the flag is set,any program not already in
  6854.  
  6855. interactive tracing mode will enter it immediately. The internal trace option
  6856.  
  6857. is set to RESULTS unless it is currently set to INTERMEDIATES or SCAN,in which
  6858.  
  6859. case it remains unchanged. Programs invoked while the external tracing flag is
  6860.  
  6861. set will begin executing in interactive tracing mode.
  6862.  
  6863.  
  6864.  
  6865. The external tracing flag provides a way to regain control over programs that
  6866.  
  6867. are caught in loops or are otherwise unresponsive. Once a program enters
  6868.  
  6869. interactive tracing mode,the user can step through the program statements and
  6870.  
  6871. diagnose the problem. There is one caveat,though:external tracing is global
  6872.  
  6873. flag,so all currently-active programs are affected by it. The tracing flag
  6874.  
  6875. remains set until it is cleared using the "te" command utility. Each program
  6876.  
  6877. maintains an internal copy of the last state of the tracing flag,and sets its
  6878.  
  6879. tracing option to OFF when it observes that the tracing flag has been cleared.
  6880.  
  6881.  
  6882.  
  6883. INTERRUPTS
  6884.  
  6885.  
  6886.  
  6887. ARexx maintains an internal interrupt system that can be used to detect and
  6888.  
  6889. trap certain error conditions. When an interrupt is enabled and its
  6890.  
  6891. corresponding condition arises,a transfer of control to the label specific to
  6892.  
  6893. that interrupt occurs. This allows a program to retain control in circumstances
  6894.  
  6895. that might otherwise cause the program to terminate. The interrupt conditions
  6896.  
  6897. can caused by either synchronous events like a syntax error,or asynchronous
  6898.  
  6899. events like a "control-C" break request. Note that these internal interrupts
  6900.  
  6901. are completely separate from the hardware interrupt system managed by the EXEC
  6902.  
  6903. operating system.
  6904.  
  6905.  
  6906.  
  6907. The interrupts supported by ARexx are described below. The name assigned to
  6908.  
  6909. each is actually the label to which control will be tranferred. Thus,a SYNTAX
  6910.  
  6911. interrupt will transfer control to the label "SYNTAX:." Interrupts can be
  6912.  
  6913. enabled or disabled using the SIGNAL instruction. For example,the instruction
  6914.  
  6915. "SIGNAL ON SYNTAX" would enable the SYNTAX interrupt.
  6916.  
  6917.  
  6918.  
  6919.                                 74
  6920.  
  6921.  
  6922.  
  6923. BREAK_C. This interrupt will trap a control-C break request generated by DOS.
  6924.  
  6925. If the interrupt is not enabled,the program terminates immediately with the
  6926.  
  6927. error message "Execution halted" and returns with the error code set to 2.
  6928.  
  6929.  
  6930.  
  6931. BREAK_D. The interrupt will detect and trap a control-D break request issued by
  6932.  
  6933. DOS. The break request is ignored if the interrupt is not enabled.
  6934.  
  6935.  
  6936.  
  6937. BREAK_E. The interrupt will detect and trap a control-E break request issued by
  6938.  
  6939. DOS. The break request is ignored if the interrupt is not enabled.
  6940.  
  6941.  
  6942.  
  6943. BREAK_F. The interrupt will detect and trap a control-F break request issued by
  6944.  
  6945. DOS. The break request is ignored if the interrupt is not enabled.
  6946.  
  6947.  
  6948.  
  6949. ERROR. This interrupt is generated by any host command that returns a non-zero
  6950.  
  6951. code.
  6952.  
  6953.  
  6954.  
  6955. HALT. An external halt request will be trapped if this interrupt is enabled.
  6956.  
  6957. Otherwise,the program terminates immediately with the error message "Execution
  6958.  
  6959. halted" and returns with the error code set to 2.
  6960.  
  6961.  
  6962.  
  6963. IOERR. Errors detected by the I/O system will be trapped if this interrupt is
  6964.  
  6965. enabled.
  6966.  
  6967.  
  6968.  
  6969. NOVALUE. An interrupt will occur if an uninitialized variable is used while
  6970.  
  6971. this condition is enabled. The usage could be within an expression,in the UPPER
  6972.  
  6973. instruction,or with the VALUE()built-in function.
  6974.  
  6975.  
  6976.  
  6977. SYNTAX. A syntax or execution error will generate this interrupt. Not all
  6978.  
  6979. errors such errors can be trapped,however. In particular,certain errors
  6980.  
  6981. occurring before a program is actually executing,and those detected by the
  6982.  
  6983. ARexx external interface,cannot be trapped by the SYNTAX interrupt.
  6984.  
  6985.  
  6986.  
  6987. When an interrupt forces a transfer of control,all of the currently active
  6988.  
  6989. control ranges are dismantled,and the interrupt that caused the transfer is
  6990.  
  6991. disabled. This latter action is necessary to prevent a possible recursive
  6992.  
  6993. interrupt loop. Only the control structures in the current environment are
  6994.  
  6995. affected,so an interrupt generated within a function will not affect the
  6996.  
  6997. caller's environment.
  6998.  
  6999.  
  7000.  
  7001. SPECIAL VARIABLES. Two special variables are affected when an interrupt occurs.
  7002.  
  7003. The variable SIGL is always set to the current line number before the transfer
  7004.  
  7005. of control takes place,so that the program can determine which source line was
  7006.  
  7007. being executed. When an ERROR or SYNTAX interrupt occurs,the variable RC is set
  7008.  
  7009. to the error code that caused the condition. For ERROR interrupts this value
  7010.  
  7011. will be a command return code,and can usually be interpreted as an error
  7012.  
  7013. severity level. The value for SYNTAX interrupts is always an ARexx error code.
  7014.  
  7015.  
  7016.  
  7017. Interrupts are useful primarily to allow a program to take special
  7018.  
  7019. error-recovery actions. Such actions might involve informing external programs
  7020.  
  7021. that an error ocurred,or simply reporting further diagnostics to help in
  7022.  
  7023. isolating the problem. In the following example,the program issues a "message"
  7024.  
  7025. command to an external host called "MyEdit" whenever a syntax error is
  7026.  
  7027. detected:
  7028.  
  7029.  
  7030.  
  7031.                                 75
  7032.  
  7033.  
  7034.  
  7035.         /* A macro program for 'MyEdit'                 */
  7036.  
  7037.         signal on syntax        /* enable interrupt     */
  7038.  
  7039.           .
  7040.  
  7041.           . (normal processing)
  7042.  
  7043.           .
  7044.  
  7045.         exit
  7046.  
  7047.         syntax:                 /* syntax error detected*/
  7048.  
  7049.            address 'MyEdit'
  7050.  
  7051.            'message' 'error' rc errortext(rc)
  7052.  
  7053.            exit 10
  7054.  
  7055.  
  7056.  
  7057.                                 76
  7058.  
  7059.  
  7060.  
  7061.                         CHAPTER 8 PARSING AND TEMPLATES
  7062.  
  7063.  
  7064.  
  7065. Parsing is a operation that extracts substrings from a string and assigns them
  7066.  
  7067. to variables. It corresponds roughly to the notion of a "formatted read" used
  7068.  
  7069. in other languages,but has been generalized in the several ways. Parsing is
  7070.  
  7071. performed using the PARSE instruction or its variants ARG and PULL. The input
  7072.  
  7073. for the operation is called the parse string and can come from several sources;
  7074.  
  7075. these source options are described with the PARSE instruction in Chapter 4.
  7076.  
  7077.  
  7078.  
  7079. Parsing is controlled by a template,a group of tokens that specifies both the
  7080.  
  7081. variables to be given values and the way to determine the value strings.
  7082.  
  7083. Templates were described briefly with the PARSE instruction;the present chapter
  7084.  
  7085. presents a more formal description of their structure and operation.
  7086.  
  7087.  
  7088.  
  7089. TEMPLATE STRUCTURE
  7090.  
  7091.  
  7092.  
  7093. The tokens that are valid in a template are symbols,strings,operators,
  7094.  
  7095. parentheses,and commas. Any blanks that may be present as separators are
  7096.  
  7097. removed before the template is processed. The tokens in a template ultimately
  7098.  
  7099. serve to specify one of the two basic template objects:
  7100.  
  7101.  
  7102.  
  7103. Markers determine a scan position within the parse string,and
  7104.  
  7105. Targets are symbols to be assigned a value.
  7106.  
  7107.  
  7108.  
  7109. With these objects in mind,the parsing process can be described as one of
  7110.  
  7111. associating with each target a starting and ending position in the parse
  7112.  
  7113. string. The substring between these positions then becomes the value for the
  7114.  
  7115. target.
  7116.  
  7117.  
  7118.  
  7119. MARKETS. There are three types of marker objects:
  7120.  
  7121.  
  7122.  
  7123. ABSOLUTE markers specify an actual index position in the parse string,
  7124.  
  7125. RELATIVE markers specify a positive or negative offset from the current
  7126.  
  7127. position,and
  7128.  
  7129. PATTERN markers specify a position implicitly,by matching the pattern against
  7130.  
  7131. the parse string beginning at the current scan position.
  7132.  
  7133.  
  7134.  
  7135. TARGETS. Targets,like markers,can affect the scan position if value strings are
  7136.  
  7137. being extracted by tokenization. Parsing by tokenization extracts words(tokens)
  7138.  
  7139. from the parse string, and is used whenever a target is followed immediately
  7140.  
  7141.  
  7142.  
  7143.                                 77
  7144.  
  7145.  
  7146.  
  7147. by another target. During tokenization the current scan position is advanced
  7148.  
  7149. past any blanks to the start of the next word. The ending index is the position
  7150.  
  7151. just past the end of the word,so that the value string has neither leading nor
  7152.  
  7153. trailing blanks.
  7154.  
  7155.  
  7156.  
  7157. TEMPLATE OBJECTS
  7158.  
  7159.  
  7160.  
  7161. Each template object is specified by one or more tokens,which have the
  7162.  
  7163. following interpretations.
  7164.  
  7165.  
  7166.  
  7167. SYMBOLS. A symbol token may specify either a target or a marker object. If it
  7168.  
  7169. follows an operator token(+,-,or=),it represents a marker,and the symbol value
  7170.  
  7171. is used as an absolute or relative position. Symbols enclosed in parentheses
  7172.  
  7173. specify pattern markers,and the symbol value is used as the pattern string.
  7174.  
  7175.  
  7176.  
  7177. If neither of the preceding cases applies and the symbol is a variable,then it
  7178.  
  7179. specifies a target. Fixed symbols always specify absolute markers and must be
  7180.  
  7181. whole numbers,except for the period(.)symbol which defines a placeholder
  7182.  
  7183. target.
  7184.  
  7185.  
  7186.  
  7187. STRINGS. A string token always represents a pattern marker.
  7188.  
  7189.  
  7190.  
  7191. PARENTHESES. A symbol enclosed in parentheses is a pattern marker,and the value
  7192.  
  7193. of the symbol is used as the pattern string. While the symbol may be either
  7194.  
  7195. fixed or variable,it will usually be a variable,since a fixed pattern could be
  7196.  
  7197. given more simply as a string.
  7198.  
  7199.  
  7200.  
  7201. OPERATORS. The three operators "+,"-,"and "=" are valid within a template,and
  7202.  
  7203. must be followed by a fixed or variable symbol. The value of the symbol is used
  7204.  
  7205. as a marker and must therefore represent a whole number. The "+" and "-"
  7206.  
  7207. operators signify a relative marker,whose value is negated by the "-" operator.
  7208.  
  7209. The "=" operator indicates an absolute marker,and is optional if the marker is
  7210.  
  7211. defined by a fixed symbol.
  7212.  
  7213.  
  7214.  
  7215. COMMAS. The comma(,)marks the end of a template,and is used as a separator when
  7216.  
  7217. multiple templates are provided with an instruction. The interpreter obtains a
  7218.  
  7219. new parse string before processing each succeeding template. For some source
  7220.  
  7221. options,the new string will be identical to the previous one. The ARG,EXTERNAL,
  7222.  
  7223. and PULL options will generally supply a different string,as will the VAR
  7224.  
  7225. option if the variable has been modified.
  7226.  
  7227.  
  7228.  
  7229. THE SCANNING PROCESS
  7230.  
  7231.  
  7232.  
  7233. Scan positions are expressed as an index in the parse string,and can range from
  7234.  
  7235. 1(the start of the string)to the length of the string plus 1(the end). An
  7236.  
  7237. attempt to set the scan position before the start or after the end of the
  7238.  
  7239. string instead sets it to the beginning or end,respectively.
  7240.  
  7241.  
  7242.  
  7243. The substring specified by two scan indices includes the characters from the
  7244.  
  7245. starting position up to,but not including,the ending position. For example,the
  7246.  
  7247. indices 1 and 10 specify characters 1-9 in the parse string. One additional
  7248.  
  7249. rule is applied if the second scan index is less than or equal to the first: in
  7250.  
  7251. this case the remainder of the parse string is used as the substring. This
  7252.  
  7253. means that a template specificaiton like
  7254.  
  7255.                                 78
  7256.  
  7257.  
  7258.  
  7259.         parse arg 1 all 1 first second
  7260.  
  7261.  
  7262.  
  7263. will assign the entire parse string to the variable ALL. Of course,if the
  7264.  
  7265. current scan index is already at the end of the parse string,then the remainder
  7266.  
  7267. is just the null string.
  7268.  
  7269.  
  7270.  
  7271. When a pattern marker is matched against the parse string,the marker position
  7272.  
  7273. is the index of the first character of the matched pattern,or the end of the
  7274.  
  7275. string if no match was found. The pattern is removed from the string whenever a
  7276.  
  7277. match is found. This is the only operation that modifies the parse string
  7278.  
  7279. during the parsing process.
  7280.  
  7281.  
  7282.  
  7283. Templates are scanned from left to right with the initial scan index set to 1,
  7284.  
  7285. the start of the parse string. The scan position is updated each time a marker
  7286.  
  7287. object is encountered,according to the type and value of the marker. Whenever a
  7288.  
  7289. target object is found,the value to be assigned is determined by examining the
  7290.  
  7291. next template object. If the next object is another target,the value string is
  7292.  
  7293. determined by tokenizing the parse string. Otherwise,the current scan position
  7294.  
  7295. is used as the start of the value string,and the position specified by the
  7296.  
  7297. following marker is used as the end point.
  7298.  
  7299.  
  7300.  
  7301. The scan continous until all of the objects in the template have been used.
  7302.  
  7303. Note that every target will be assigned a value;once the parse string has been
  7304.  
  7305. exhausted,the null string is assigned to any remaining targets.
  7306.  
  7307.  
  7308.  
  7309. TEMPLATES IN ACTION
  7310.  
  7311.  
  7312.  
  7313. The preceding section is rather abstract,so let's look now at some examples of
  7314.  
  7315. parsing with templates.
  7316.  
  7317.  
  7318.  
  7319. PARSING BY TOKENIZATION
  7320.  
  7321.  
  7322.  
  7323. Computer programs frequently require splitting a string into its component
  7324.  
  7325. words or tokens. This is easily accomplished with a template consisting
  7326.  
  7327. entirely of variables(targets).
  7328.  
  7329.  
  7330.  
  7331.         /* Assume "hammer 1 each $600.00" was entered   */
  7332.  
  7333.         pull item qty untils cost .
  7334.  
  7335.  
  7336.  
  7337. In this example the input line from the PULL instruction is split into words
  7338.  
  7339. and assigned to the variables in the template. The variable item receives the
  7340.  
  7341. value "hammer," qty is set to "1," units is set to "each," and cost gets the
  7342.  
  7343. value "$600.00." The final placeholder(.) is given a null value,since there are
  7344.  
  7345. only four words in the input. However,it forces the preceding variable cost to
  7346.  
  7347. be given a tokenized value. If the placeholder were omitted,the remainder of
  7348.  
  7349. the parse string would be assigned to cost,which would then have a leading
  7350.  
  7351. blank.
  7352.  
  7353.  
  7354.  
  7355. In the next example,the first word of a string is removed and the remainder is
  7356.  
  7357. placed back in the string. The process continues until no more words are
  7358.  
  7359. extracted.
  7360.  
  7361.  
  7362.  
  7363.                                 79
  7364.  
  7365.  
  7366.  
  7367.         /* Assume "result" contains a string of words   */
  7368.  
  7369.         do forever
  7370.  
  7371.            /* Get first word of string                  */
  7372.  
  7373.            parse var result first result
  7374.  
  7375.            if first == '' then leave
  7376.  
  7377.            /* ... process words ...                     */
  7378.  
  7379.            end
  7380.  
  7381.  
  7382.  
  7383. PATTERN PARSING
  7384.  
  7385.  
  7386.  
  7387. The next example uses pattern markers to extract the desired fields. The
  7388.  
  7389. "pattern" in this case is very simple -- just a single character -- but in
  7390.  
  7391. general can be an arbitrary string of any length. This form of parsing is
  7392.  
  7393. useful whenever delimiter characters are present in the parse string.
  7394.  
  7395.  
  7396.  
  7397.         /* Assume an argument string "12,34.5,1         */
  7398.  
  7399.         arg hours ',' rate ',' withhold
  7400.  
  7401.  
  7402.  
  7403. Keep in mind that the pattern is actually removed from the parse string when a
  7404.  
  7405. match is found. If the parse string is scanned again from the beginning,the
  7406.  
  7407. length and structure of the string may be different than at the start of the
  7408.  
  7409. parsing process. However,the original source of the string is never modified.
  7410.  
  7411.  
  7412.  
  7413. POSITIONAL MARKERS
  7414.  
  7415.  
  7416.  
  7417. Parsing with positional markers is used whenever the fields of interest are
  7418.  
  7419. known to be in certain positions in a string. In the next example,the records
  7420.  
  7421. being processed contain a variable length field. The starting position and
  7422.  
  7423. length of the field are given in the first part of the record,and a variable
  7424.  
  7425. positional marker is used to extact the desired field.
  7426.  
  7427.  
  7428.  
  7429.         /* records look like:                           */
  7430.  
  7431.         /* start:   1-5                                 */
  7432.  
  7433.         /* length:  6-10                                */
  7434.  
  7435.         /* name:    @(start,length)                     */
  7436.  
  7437.         parse value record with 1 start +5 length +5 =start name +length
  7438.  
  7439.  
  7440.  
  7441. The "=start" sequence in the above example is an absolute marker whose value is
  7442.  
  7443. the position paced in the variable start earlier in the scan. The "+length"
  7444.  
  7445. sequence supplies the effective length of the field.
  7446.  
  7447.  
  7448.  
  7449. MULTIPLE TEMPLATES
  7450.  
  7451.  
  7452.  
  7453. It is sometimes useful to specify more than one template with an instruction,
  7454.  
  7455. which can be done by separating the templates with a comma. In this next
  7456.  
  7457. example,the ARG instruction(or PARSE UPPER ARG)is used to access the argument
  7458.  
  7459. strings provided when the program was called. Each template accesses the
  7460.  
  7461. succeeding argument string.
  7462.  
  7463.  
  7464.  
  7465.                                 80
  7466.  
  7467.  
  7468.  
  7469.         /* Assume arguments were ('one two',12,sort)    */
  7470.  
  7471.         arg first second,amount,action,option
  7472.  
  7473.  
  7474.  
  7475. The first template consists of the variables first and second,which are set to
  7476.  
  7477. the values "one" and "two,"respectively. In the next two templates amount gets
  7478.  
  7479. the value "12" and action is set to "SORT". The last template consists of the
  7480.  
  7481. variable "option,"which is set to the null string,since only three arguments
  7482.  
  7483. were available.
  7484.  
  7485.  
  7486.  
  7487. When multiple templates are used with the EXTERNAL or PULL source options,each
  7488.  
  7489. additional template requests an additional line of input from the user. In the
  7490.  
  7491. next example two lines of input are read:
  7492.  
  7493.  
  7494.  
  7495.         /* read last,first,and middle names and ssn     */
  7496.  
  7497.         pull last ',' first middle,ssn
  7498.  
  7499.  
  7500.  
  7501. The first input line is expected to have three words,the first of which is
  7502.  
  7503. followed by a comma,which are assigned to the variables last,first,and middle.
  7504.  
  7505. The entire second input line is assigned to the variable ssn.
  7506.  
  7507.  
  7508.  
  7509. Multiple templates can be useful even with a source option that returns the
  7510.  
  7511. identical parse string. If the first template included pattern markers that
  7512.  
  7513. altered the parse string,the subsequent templates could still access the
  7514.  
  7515. original string. Note that subsequent parse strings obtained from the VALUE
  7516.  
  7517. source do not cause the expression to be reevaluated,but only retrieve the
  7518.  
  7519. prior result.
  7520.  
  7521.  
  7522.  
  7523.                                 81
  7524.  
  7525.  
  7526.  
  7527.                         CHAPTER 9 THE RESIDENT PROCESS
  7528.  
  7529.  
  7530.  
  7531. This chapter describes some of the capabilities of the ARexx resident process,
  7532.  
  7533. a global communications and resources manager. The material presented here is
  7534.  
  7535. directed to the general user;Chapter 10 covers these topics in greater depth
  7536.  
  7537. for software developers who wish to integrate ARexx with other applications
  7538.  
  7539. programs.
  7540.  
  7541.  
  7542.  
  7543. The resident process must be active before any ARexx programs can be run. It
  7544.  
  7545. announces its presence to the system by opening a public message port named
  7546.  
  7547. "REXX,"so applications programs that use ARexx should check for the presence of
  7548.  
  7549. this port. If the port is not open,the user can either be informed that the
  7550.  
  7551. macro processor is not available,or else the applications program can start up
  7552.  
  7553. the resident process. The latter option can be done using the rexxmast command.
  7554.  
  7555.  
  7556.  
  7557. The primary function of the resident process is to launch ARexx programs. When
  7558.  
  7559. an applications program sends a "command" or "function" message to the "REXX"
  7560.  
  7561. port,the resident process creates a new DOS process to execute the program, and
  7562.  
  7563. forwards the invocation message to newly created process. It also creates a new
  7564.  
  7565. instance of the ARexx global data structure,which links together all of the
  7566.  
  7567. structures manipulated by the program.
  7568.  
  7569.  
  7570.  
  7571. In addition to launching programs,the resident process managers various
  7572.  
  7573. resources used by ARexx. These resources include a list of available function
  7574.  
  7575. libraries called the Library List,a list of(name,value)pairs called the Clip
  7576.  
  7577. List,and a list of the currently active ARexx programs. Built-In functions are
  7578.  
  7579. available to manipulate the Library List and Clip List from within an ARexx
  7580.  
  7581. program. Applications programs can modify a resource list either by sending a
  7582.  
  7583. request packet to the resident process or by direct manipulation of the list.
  7584.  
  7585.  
  7586.  
  7587. COMMAND UTILITIES
  7588.  
  7589.  
  7590.  
  7591. ARexx is supplied with a number of command utilities to provide various control
  7592.  
  7593. functions. These are executable modules that can be run from the CLI,and should
  7594.  
  7595. reside in the system command(C:)directory for convenience. These commands are
  7596.  
  7597. relevant only when the ARexx resident process is active.
  7598.  
  7599.  
  7600.  
  7601. The functions performed by these utilities may also be available from within an
  7602.  
  7603. applications program. All of the utilities are implemented by sending message
  7604.  
  7605. packets to the resident process,so an application designed to work closely with
  7606.  
  7607. ARexx could easily provide these functions as part of its control menu.
  7608.  
  7609.  
  7610.  
  7611. HI
  7612.  
  7613. Usage:HI
  7614.  
  7615. Sets the global halt flag,which causes all active programs to receive an
  7616.  
  7617. external halt request. Each program will exit immediately unless its HALT
  7618.  
  7619. interrupt has been enabled. The halt flag does not remain set,but is cleared
  7620.  
  7621. automatically after all current programs have received the request.
  7622.  
  7623.  
  7624.  
  7625.                                 83
  7626.  
  7627.  
  7628.  
  7629. RX
  7630.  
  7631. Usage:RX name[arguments]
  7632.  
  7633. This command launches an ARexx program. If the specified name includes an
  7634.  
  7635. explicit path,only that directory is searched for the program;otherwise,the
  7636.  
  7637. current directory and the system REXX: device are checked for a program with
  7638.  
  7639. the given name. The optional argument string is passed to the program.
  7640.  
  7641.  
  7642.  
  7643. RXSET
  7644.  
  7645. Usage:RXSET name value
  7646.  
  7647. Adds a(name,value)pair to the Clip List. Name strings are assumed to be in
  7648.  
  7649. mixed case. If a pair with the same name already exists,its value is replaced
  7650.  
  7651. with the current string. If a name without a value string is given,the entry is
  7652.  
  7653. removed from the Clip List.
  7654.  
  7655.  
  7656.  
  7657. RXC
  7658.  
  7659. Usage:RXC
  7660.  
  7661. Closes the resident process. The "REXX" public port is withdrawn immediately,
  7662.  
  7663. and the resident process exits as soon as the last ARexx program finishes. No
  7664.  
  7665. new programs can be launched after a "close" request.
  7666.  
  7667.  
  7668.  
  7669. TCC
  7670.  
  7671. Usage:TCC
  7672.  
  7673. Closes the global tracing console as soon as all active programs are no longer
  7674.  
  7675. using it. All read read requests queued to the console must be satisfied before
  7676.  
  7677. it can be closed.
  7678.  
  7679.  
  7680.  
  7681. TCO
  7682.  
  7683. Usage:TCO
  7684.  
  7685. Open the global tracing console. The tracing output from all active programs is
  7686.  
  7687. diverted automatically to the new console. The console window can be moved and
  7688.  
  7689. resized by the user,and can be closed with the "TCC" command.
  7690.  
  7691.  
  7692.  
  7693. TE
  7694.  
  7695. Usage:TE
  7696.  
  7697. Clears the global tracing flag,which forces the tracing mode to OFF for all
  7698.  
  7699. active ARexx programs.
  7700.  
  7701.  
  7702.  
  7703. TS
  7704.  
  7705. Usage:TS
  7706.  
  7707. Starts interactive tracing by setting the external trace flag,which forces all
  7708.  
  7709. active ARexx programs into interactive tracing mode. Programs will start
  7710.  
  7711. producing trace output and will pause after the next statement. This command is
  7712.  
  7713. useful for regaining control over programs caught in infinite loops or
  7714.  
  7715. otherwise misbehaving. The trace flag remains set until cleared by the TE
  7716.  
  7717. command,so subsequent program invocations will begin executing in interactive
  7718.  
  7719. tracing mode.
  7720.  
  7721.  
  7722.  
  7723.                                 84
  7724.  
  7725.  
  7726.  
  7727. RESOURCE MANAGEMENT
  7728.  
  7729.  
  7730.  
  7731. Individual ARexx programs manage their internal memory allocation and I/O file
  7732.  
  7733. resources,but some resources need to be available to all programs. The
  7734.  
  7735. management of these global resources is one of the major functions of the
  7736.  
  7737. resident process. Global resources are maintained as doubly-linked lists,in
  7738.  
  7739. keeping with the general design principles of the EXEC operating system. Linked
  7740.  
  7741. lists provide a flexible and open mechanism for resource management,and help
  7742.  
  7743. avoid the built-in limits common with other approaches.
  7744.  
  7745.  
  7746.  
  7747. THE GLOBAL TRACING CONSOLE
  7748.  
  7749.  
  7750.  
  7751. The tracing output from an ARexx program usually goes to the standard output
  7752.  
  7753. stream STDOUT,and is therefore interleaved with the normal output of the
  7754.  
  7755. program. Since this may be confusing at times,a global trace console can be
  7756.  
  7757. opened to display only tracing output. The console can be opened using the tco
  7758.  
  7759. command utility or be sending an RXTCOPN request packet to the resident
  7760.  
  7761. process. ARexx programs will automatically divert their tracing output to the
  7762.  
  7763. new window,which is opened as a standard AmigaDOS console. The user can move it
  7764.  
  7765. and resize it as required.
  7766.  
  7767.  
  7768.  
  7769. The tracing console also serves as the input stream for programs during
  7770.  
  7771. interactive tracing. When a program pauses for tracing input,the input line
  7772.  
  7773. must be entered at the trace console. Any number of programs may use the
  7774.  
  7775. tracing console simultaneously,although it is generally recommended that only
  7776.  
  7777. one program at a time be traced.
  7778.  
  7779.  
  7780.  
  7781. The tracing console can be closed using the tcc command or by sending an
  7782.  
  7783. RXTCCLS request packet to the resident process. The closing is delayed until
  7784.  
  7785. all read requests to the console have been satisfied. Only when all of the
  7786.  
  7787. active programs indicate that they are no longer using the console will it
  7788.  
  7789. actually be closed.
  7790.  
  7791.  
  7792.  
  7793. THE LIBRARY LIST
  7794.  
  7795.  
  7796.  
  7797. The resident process maintains a Library List of the function libraries and
  7798.  
  7799. function hosts currently available to ARexx programs. This list is used to
  7800.  
  7801. resolve all references to external functions. Each entry has an associated
  7802.  
  7803. search priority in the range 100 to -100,with the higher-valued entries being
  7804.  
  7805. searched first until the requested function is found. The list is searched by
  7806.  
  7807. calling each entry,using the appropriate protocol,until the return code
  7808.  
  7809. indicates that the function was found.
  7810.  
  7811.  
  7812.  
  7813. The two types of entities maintained by the list are quite different in some
  7814.  
  7815. respects,but the ultimate way in which a function call is resolved is
  7816.  
  7817. transparent to the calling program. A function library is a collection of
  7818.  
  7819. functions organized as an Amiga shared library,while a function host is a
  7820.  
  7821. separate task that manages a message port. Function libraries are called as
  7822.  
  7823. part of the ARexx interpreter's task context,but calls to function hosts are
  7824.  
  7825. mediated by passing a message packet. The ARexx resident process is itself a
  7826.  
  7827. function host,and is installed in the Library List at a priority of -60.
  7828.  
  7829.  
  7830.  
  7831. The resident process provides addition and deletion operations for maintaining
  7832.  
  7833. the Library List;these operations are performed by sending an appropriate
  7834.  
  7835. message packet. The Library List is always maintained in priority order. Within
  7836.  
  7837. a given priority level any new entries are added to the end of the chain, so
  7838.  
  7839. that entries added first will be searched fist. The priority levels are
  7840.  
  7841.  
  7842.  
  7843.                                 85
  7844.  
  7845.  
  7846.  
  7847. significant if any of the libraries have duplicate function name
  7848.  
  7849. definitions,since the function located further down the search chain could
  7850.  
  7851. never be called.
  7852.  
  7853.  
  7854.  
  7855. FUNCTION LIBRARIES. Each function library entry in the Library List contains a
  7856.  
  7857. library name,a search priority,an entry point offset,and a version number. The
  7858.  
  7859. library name must refer to a standard Amiga shared library residing in the
  7860.  
  7861. system LIBS: directory so that it can be loaded when needed. Function libraries
  7862.  
  7863. can be created and maintained by users or applications developers;Chapter 10
  7864.  
  7865. has information on their design and implementation.
  7866.  
  7867.  
  7868.  
  7869. The "query" function is the library entry point that is actually called by the
  7870.  
  7871. interpreter. It must be specified as an integer offset(e.g. "-30")from the
  7872.  
  7873. library base. The return code from the query call then indicates whether the
  7874.  
  7875. desired function was found;it it was,the function is called with the parameters
  7876.  
  7877. passed by the interpreter and the function result is returned to the caller.
  7878.  
  7879. Otherwise,the search continues with the next entry in the list. In either event
  7880.  
  7881. the library is closed to await the next call.
  7882.  
  7883.  
  7884.  
  7885. A note of caution: not every Amiga shared library can be used as a function
  7886.  
  7887. library. Function libraries must have a special entry point to perform the
  7888.  
  7889. dynamic linking required to access the functions from within ARexx. Each
  7890.  
  7891. library should include documentation providing its version number and the
  7892.  
  7893. integer offset to its "query" entry point.
  7894.  
  7895.  
  7896.  
  7897. FUNCITON HOSTS. The name associated with a function host is the name of its
  7898.  
  7899. public message port. Function calls are passed to the host as a message packet;
  7900.  
  7901. it is then up to the individual host to determine whether the specified
  7902.  
  7903. function name is one that it recognizes. The name resolution is completely
  7904.  
  7905. internal to the host,so function hosts provide a natural gateway mechanism for
  7906.  
  7907. implementing remote procedure calls to other machines in a network.
  7908.  
  7909.  
  7910.  
  7911. THE CLIP LIST
  7912.  
  7913.  
  7914.  
  7915. The Clip List maintains a set of(name,value)pairs that may be used for a
  7916.  
  7917. variety of purposes. Each entry in the list consists of a name and a value
  7918.  
  7919. string,and may be located by name. Since the Clip List is publicly accessible,
  7920.  
  7921. it may be used as a general clipboard-like mechanism for intertask
  7922.  
  7923. communication. In general,the names used should be chosen to be unique to an
  7924.  
  7925. application to prevent collisions with other programs. Any number of entries
  7926.  
  7927. may be posted to the list.
  7928.  
  7929.  
  7930.  
  7931. One potential application for the Clip List is as a mechanism for loading
  7932.  
  7933. predefined constants into an ARexx program. The language definition does not
  7934.  
  7935. include a facility comparable to the "header file" preprocessor in the "C"
  7936.  
  7937. language. However,consider a string in the Clip List of the form
  7938.  
  7939.  
  7940.  
  7941.         pi=3.14159; e=2.718; sqrt2=1.414 ...
  7942.  
  7943.  
  7944.  
  7945. i.e.,a series of assignments separated by semicolons. In use,such a string
  7946.  
  7947. could be retrieved by name using the Built-In function GETCLIP()and then
  7948.  
  7949. INTERPRETed within the program. The assignment statements within the string
  7950.  
  7951. would then create the required constant definitions. The following program
  7952.  
  7953. fragment illustrates the process::
  7954.  
  7955.  
  7956.  
  7957.                                 86
  7958.  
  7959.  
  7960.  
  7961.         /* assume a string called "numbers" is available*/
  7962.  
  7963.         numbers=getclip('numbers')    /* case-sensitive */
  7964.  
  7965.         interpret numbers             /* ... assignments*/
  7966.  
  7967.         ...
  7968.  
  7969.  
  7970.  
  7971. More generally,the strings would not be restricted to contain only assignment
  7972.  
  7973. statements,but could include any valid ARexx statements. The Clip List could
  7974.  
  7975. thus provide a series of programs for initializations or other processing
  7976.  
  7977. tasks.
  7978.  
  7979.  
  7980.  
  7981. The resident process supports addition and deletion operations for maintaining
  7982.  
  7983. the Clip List. The names in the(name,value)pairs are assumed to be in mixed
  7984.  
  7985. cases,and are maintained to be unique in the list. An attempt to add a string
  7986.  
  7987. with an existing name will simply update the value string. The name and value
  7988.  
  7989. strings are copied when an entry is posted to the list,so the program that adds
  7990.  
  7991. an entry is not required to maintain the strings.
  7992.  
  7993.  
  7994.  
  7995. Entries posted to the Clip List remain available until explicitly removed. The
  7996.  
  7997. Clip List is automatically released when the resident process exits.
  7998.  
  7999.  
  8000.  
  8001.                                 87
  8002.  
  8003.  
  8004.  
  8005.                         CHAPTER 10 INTERFACING TO AREXX
  8006.  
  8007.  
  8008.  
  8009. This chapter discusses the issues involved in designing and implementing an
  8010.  
  8011. interface between ARexx and an external applications program. The material
  8012.  
  8013. presented here is directed to software developers,so a high degree of
  8014.  
  8015. familiarity with programming the Amiga in either "C" or assembly-language is
  8016.  
  8017. assumed.
  8018.  
  8019.  
  8020.  
  8021. ARexx can interact with external programs in several ways. The command
  8022.  
  8023. interface is used to communicate with an external program running as a separate
  8024.  
  8025. task in the Amiga's multitasking environment. The interaction takes place by
  8026.  
  8027. passing messages between public message ports,and is in many ways similar to
  8028.  
  8029. the interaction of a program with Intution,the Amiga's window and menu manager.
  8030.  
  8031. The command interface provides both a means of sharing data and a method of
  8032.  
  8033. controlling an applications program.
  8034.  
  8035.  
  8036.  
  8037. Function libraries provide a mechanism for calling external code as part of an
  8038.  
  8039. ARexx program's tasks context. The linkages for such calls are established
  8040.  
  8041. dynamically at run time rather than when the program is linked,so each function
  8042.  
  8043. library must include an entry point to match function names with the address of
  8044.  
  8045. the function to be called.
  8046.  
  8047.  
  8048.  
  8049. Function hosts are external tasks that manage a public message port for
  8050.  
  8051. communicating with ARexx or other programs. Both function hosts and function
  8052.  
  8053. libraries are managed by the Library List,which provides a prioritized search
  8054.  
  8055. mechanism for resolving function names. Function hosts may be used as a gateway
  8056.  
  8057. into a metwork to provide a remote procedure call facility. ARexx imposes no
  8058.  
  8059. constraints on the internal operations of a function host,except to require
  8060.  
  8061. that message packets be returned with an appropriate code.
  8062.  
  8063.  
  8064.  
  8065. The resident process acts as the hub for communications between ARexx and
  8066.  
  8067. external entities. It opens and manages a public message port named "REXX," and
  8068.  
  8069. provides a number of support services. Note that the resident process is itself
  8070.  
  8071. a "host application" whose function it is to launch ARexx programs and maintain
  8072.  
  8073. global resources. The activation structures for all ARexx programs are linked
  8074.  
  8075. into a list maintained by the resident process,and in principle their compete
  8076.  
  8077. internal states are accessible to external programs.
  8078.  
  8079.  
  8080.  
  8081. The ARexx interpreter is structured as an Amiga shared library and includes
  8082.  
  8083. entry points specifically designed to help implement an interface to ARexx.
  8084.  
  8085. Functions are available to create and delete message packets,argument
  8086.  
  8087. strings,and other resources. Software developers are rged to use these library
  8088.  
  8089. routines whenever possible,as they provide "safe" access to the internal
  8090.  
  8091. structures. The ARexx Systems Library functions are documented in Appendix C.
  8092.  
  8093.  
  8094.  
  8095.                                 89
  8096.  
  8097.  
  8098.  
  8099. BASIC STRUCTURES
  8100.  
  8101.  
  8102.  
  8103. Most developers will need to work with only two of the data structures used by
  8104.  
  8105. ARexx. The RexxArg structure is used for all of the strings manipulated by the
  8106.  
  8107. interpreter. It is usually passed as an argstring,a pointer offset from the
  8108.  
  8109. structure base that may be treated like an ordinary string pointer. The RexxMsg
  8110.  
  8111. structure is an extension of an EXEC Message,and is the message packet used for
  8112.  
  8113. all communications with external programs.
  8114.  
  8115.  
  8116.  
  8117. ARGSTRINGS. All ARexx strings are maintained as RexxArg structures,which are
  8118.  
  8119. diagrammed in Table 10.1 below. Note that his actually a variable-length
  8120.  
  8121. structure allocated for each specific string length. String parameters are sent
  8122.  
  8123. in the form of argstrings,a pointer to the string buffer area of the RexxArg
  8124.  
  8125. structure. The string in the stucture is always given a trailing null byte,so
  8126.  
  8127. that external programs can treat argstrings like a pointer to a null-terminated
  8128.  
  8129. string. Additional data about the string(its length,hash code,and attributes)
  8130.  
  8131. are available at negative offsets from the argstring pointer.
  8132.  
  8133.  
  8134.  
  8135.                          The RexxArg Structure
  8136.  
  8137.  
  8138.  
  8139.                 STRUCTURE RexxArg,0
  8140.  
  8141.                 LONG    ra_Size         ; allocated length
  8142.  
  8143.                 UWORD   ra_Length       ; length of string
  8144.  
  8145.                 UBYTE   ra_Flags        ; attribute flags
  8146.  
  8147.                 UBYTE   ra_Hash         ; hash code
  8148.  
  8149.                 STRUCT  ra_Buff,8       ; buffer (argstring points here)
  8150.  
  8151.  
  8152.  
  8153. Library functions are available to create and delete argstrings,and for
  8154.  
  8155. converting integers into argstring format. The function CreateArgstring()
  8156.  
  8157. allocates a structure and copies a string into it,and returns an argstring
  8158.  
  8159. pointer to the structure. The function DeleteArgstring()can be used to release
  8160.  
  8161. an argstring when it is no longer needed.
  8162.  
  8163.  
  8164.  
  8165. MESSAGE PACKETS. All communications between ARexx and external programs are
  8166.  
  8167. mediated with with message packets,whose structure is diagrammed in Table 10.2
  8168.  
  8169. below. Functions are provided in the ARexx Systems Library to create,
  8170.  
  8171. initialize,and delete these message packets. Each packet sent from ARexx to an
  8172.  
  8173. external program is marked with a special pointer in its name field. This can
  8174.  
  8175. be used to distinguish the message packets from those belonging to other
  8176.  
  8177. programs,in case a message port is being shared.
  8178.  
  8179.  
  8180.  
  8181. Message packets are created using the CreateRexxMsg()function,and can be
  8182.  
  8183. released using the DeleteRexxMsg(). Note that the message packets passed by
  8184.  
  8185. ARexx to a host application(as a command,for instance)are identical to the
  8186.  
  8187. packets the host would use to invoke an ARexx program. This commonality of
  8188.  
  8189. design means that only one set of functions is needed to create and delete
  8190.  
  8191. message packets,and that external programs can use the same routines that the
  8192.  
  8193. interpreter uses to handle the packets.
  8194.  
  8195.  
  8196.  
  8197. RESOURCE NODES. A somewhat higher-level data structure called a "resource node"
  8198.  
  8199. (a RexxRsrc structure)is used extensively within ARexx to maintain resource
  8200.  
  8201. lists. These nodes are variable-length structures that include the total
  8202.  
  8203. allocated length as a field within the node,and that also provide for an
  8204.  
  8205. "auto-delete" function. This latter capability allows the address of a clean-up
  8206.  
  8207.  
  8208.  
  8209.                                 90
  8210.  
  8211.  
  8212.  
  8213. function to be associated with the node so that an entire(possibly
  8214.  
  8215. inhomogeneous)list of resource nodes can be deallocated with a single function
  8216.  
  8217. call.
  8218.  
  8219.  
  8220.  
  8221.                          The RexxMsg Structures
  8222.  
  8223.  
  8224.  
  8225.                 STRUCTURE RexxMsg,MN_SIZE
  8226.  
  8227.                 APTR    rm_TaskBlock    ; global pointer
  8228.  
  8229.                 APTR    rm_LibBase      ; library pointer
  8230.  
  8231.                 LONG    rm_Action       ; command code
  8232.  
  8233.                 LONG    rm_Result1      ; primary result
  8234.  
  8235.                 LONG    rm_Result2      ; secondary result
  8236.  
  8237.                 STRUCT  rm_Args,16*4    ; arguments (ARGO-ARG15)
  8238.  
  8239.                                      ;  the extension area
  8240.  
  8241.                 APTR    rm_PassPort     ; forwarding port
  8242.  
  8243.                 APTR    rm_CommAddr     ; host address
  8244.  
  8245.                 APTR    rm_FileExt      ; file extention
  8246.  
  8247.                 LONG    rm_Stdin        ; input stream
  8248.  
  8249.                 LONG    rm_Stdout       ; output steam
  8250.  
  8251.                 LONG    rm_avail        ; reserved
  8252.  
  8253.                 LABEL   rm_SIZEOF       ; 128 bytes
  8254.  
  8255.  
  8256.  
  8257. DESIGNING A COMMAND INTERFACE
  8258.  
  8259.  
  8260.  
  8261. The minimal command interface between ARexx and an applications program
  8262.  
  8263. requires only a public message port and a routine to process the commands
  8264.  
  8265. received. For most host applications this will require little extra machinery,
  8266.  
  8267. as the program will probably already have several message ports for key and
  8268.  
  8269. menu events,timer messages,and so on. Processing the command strings should be
  8270.  
  8271. relatively straightforward for command-oriented applications. Hosts that are
  8272.  
  8273. entirely menu-driven will require somewhat more additional programming,unless
  8274.  
  8275. commands are supported only as simulated menu events. The specific choice of
  8276.  
  8277. which commands to support is always left up to the applications designer,as
  8278.  
  8279. ARexx imposes no restrictions on the structure of the commands that can be
  8280.  
  8281. issued.
  8282.  
  8283.  
  8284.  
  8285. The basic sequence of events in the command interface begins when the host
  8286.  
  8287. sends a command invocation message to the ARexx resident process. This is
  8288.  
  8289. usually in response primitives supported by the host. When the resident process
  8290.  
  8291. receives the message packet,it spawns a new DOS process the run the macro
  8292.  
  8293. program. The command line is parsed to extract the command token(the first
  8294.  
  8295. word),and the interpreter searches for a file that matches the command name.
  8296.  
  8297.  
  8298.  
  8299. Once a macro program file has been found,it is executed by the interpreter and
  8300.  
  8301. (usually)results in one or more commands being issued back to the host
  8302.  
  8303. application's public port. The macro program waits while each command is
  8304.  
  8305. processed by the host,and takes appropriate actions if the return code
  8306.  
  8307. indicates that an error occurred. Eventually the macro program finishes and
  8308.  
  8309. returns the invocation message packet back to the host.
  8310.  
  8311.  
  8312.  
  8313. Error handling is an important consideration in the interface design. Macro
  8314.  
  8315. programs must receive return codes so that processing actions can be altered
  8316.  
  8317. when errors occur.
  8318.  
  8319.  
  8320.  
  8321.                                 91
  8322.  
  8323.  
  8324.  
  8325. Normally,the host application should not return a message packet until the
  8326.  
  8327. command has been processed and its error status in known. Hosts that support
  8328.  
  8329. two streams of commands(from the user and from the command interface)will need
  8330.  
  8331. a flag to indicate the source of each command. Errors in user commands might
  8332.  
  8333. normally be reported on the screen,but errors in ARexx commands must be
  8334.  
  8335. reported by setting the result field in the message packet.
  8336.  
  8337.  
  8338.  
  8339. Return codes should generally be chosen to follow the model of an error
  8340.  
  8341. severity level,with small integers representing relatively harmless conditions
  8342.  
  8343. and larger values indicating progressively more severe errors. This will allow
  8344.  
  8345. a characteristic failure level to be established within a macro program,so that
  8346.  
  8347. insignificant errors can be ignored. The choice of the specific return code
  8348.  
  8349. values is left to the applications designer.
  8350.  
  8351.  
  8352.  
  8353. RECEIVING COMMAND MESSAGES
  8354.  
  8355.  
  8356.  
  8357. Each host application must open a public message port to support the command
  8358.  
  8359. interface. When a macro program issues a command to the host,a message packet
  8360.  
  8361. containing the command is sent to this public port. The structure of these
  8362.  
  8363. message packets is shown in Table 10.2. The rm_Action field will be set to
  8364.  
  8365. RXCOMM,and the ARGO parameter slot will contain the command as an argstring
  8366.  
  8367. pointer. Parameter slots ARG1-ARG15 are not used for command messages. Two
  8368.  
  8369. other fields are potentially of interest: the rm_RexxTask field contains a
  8370.  
  8371. pointer to the global data structure for the program that issued the command,
  8372.  
  8373. and the rm_LibBase field has the ARexx library base address. The fields in the
  8374.  
  8375. extension area may also be of interest to the host program;these are described
  8376.  
  8377. later on. Except for setting the result fields rm_Result1 and rm_Result2,the
  8378.  
  8379. host application should not alter the message packet.
  8380.  
  8381.  
  8382.  
  8383. RESULT FIELDS
  8384.  
  8385.  
  8386.  
  8387. When the host program finishes processing the command,it must set the primary
  8388.  
  8389. result field rm_Result1 to an error severity level or zero if no errors
  8390.  
  8391. occurred. This is the field which will be assigned to the special variable RC
  8392.  
  8393. in the macro program. The secondary result field rm_Result2 should be set to
  8394.  
  8395. zero unless a result string(as described below)is being returned. The packet
  8396.  
  8397. can then be returned to the sender using the EXEC function ReplyMsg().
  8398.  
  8399.  
  8400.  
  8401. In some cases a macro program may request a result string by setting the
  8402.  
  8403. RXFB_RESULT modifier bit in the command code. If possible,the host application
  8404.  
  8405. should then return the result as an argstring pointer in the secondary result
  8406.  
  8407. field rm-Result2. A result string should only be returned if explicitly
  8408.  
  8409. requested and if no errors occurred during the call(rm_Result1 set to zero).
  8410.  
  8411. Failure to observe these rules will result either in memory loss or in
  8412.  
  8413. corruption of the system free-memory list.
  8414.  
  8415.  
  8416.  
  8417. MULTIPLE HOST PROCESSES
  8418.  
  8419.  
  8420.  
  8421. Many applications programs support concurrent activities on several sets of
  8422.  
  8423. data. For example,most text editors allow several files to be edited at once. A
  8424.  
  8425. command issued from a particular instance of the editor might invoke an ARexx
  8426.  
  8427. macro program,so clearly any commands issued from that macro would have to be
  8428.  
  8429. directed to the correct instance of the editor. ARexx provides for this by
  8430.  
  8431. allowing the applications program to declare an initial host address when a
  8432.  
  8433. program is invoked. A separate message port would be opened for each instance
  8434.  
  8435. of the host application,and this port would be named as the initial host
  8436.  
  8437. address for all invocations from that instance. In the example above,if the
  8438.  
  8439. editor opened two ports named "MyEdit1" and "MyEdit2,"then programs invoked by
  8440.  
  8441. the "MyEdit1" instance would send commands back to the "MyEdit1" port.
  8442.  
  8443.  
  8444.  
  8445. MULTIPLE MESSAGE PORTS. Host applications are not limited to having a single
  8446.  
  8447. message port for commands. If several different kinds of commands are to be
  8448.  
  8449. received,it might be appropriate to set up more than one port. Macro programs
  8450.  
  8451. would then use the ADDRESS instruction to direct commands to the appropriate
  8452.  
  8453. port. The different ports could be used simultaneously,since ARexx programs
  8454.  
  8455. execute as separate tasks.
  8456.  
  8457.  
  8458.  
  8459. INVOKING AREXX PROGRAMS
  8460.  
  8461.  
  8462.  
  8463. ARexx programs are invoked by sending a message packet to the resident process.
  8464.  
  8465. Programs may be invoked as either a command or as a function. The command mode
  8466.  
  8467. of invocation is generally simpler,as it requires setting only a few fields in
  8468.  
  8469. the message packet.
  8470.  
  8471.  
  8472.  
  8473. MESSAGE PACKETS
  8474.  
  8475.  
  8476.  
  8477. The structure of the message packet supported by ARexx is shown in Table 10.2.
  8478.  
  8479. This structure provides fields for passing arguments and for specifying
  8480.  
  8481. overrides to various internal defaults. The packets are cleared(set to 0)when
  8482.  
  8483. allocated,and the client-supplied fields are never altered by ARexx. Message
  8484.  
  8485. packets can be reused after being returned,and generally only one is required.
  8486.  
  8487.  
  8488.  
  8489. COMMAND(ACTION)CODE. The rm_Action field of the message packet determines the
  8490.  
  8491. mode of invocation. It can be set to either RXCOMM or RXFUNC for command or
  8492.  
  8493. function mode,respectively. Several modifier flags can be used with the command
  8494.  
  8495. code;these are described later in this chapter.
  8496.  
  8497.  
  8498.  
  8499. ARGUMENT STRINGS. Command strings,function names,and argument strings must be
  8500.  
  8501. supplied as argstrings. Strings can be conveniently packaged into argstrings
  8502.  
  8503. using the CreateArgstring()library function,which takes a string pointer and a
  8504.  
  8505. length as its arguments. Argstrings point to a null-terminated string and may
  8506.  
  8507. be treated like an ordinary string pointer in most cases. In principle,a host
  8508.  
  8509. application could build the argstrings directly,but since the strings must
  8510.  
  8511. remain unchanged for the duration of a ARexx program,the host might need to
  8512.  
  8513. maintain many such structures.
  8514.  
  8515.  
  8516.  
  8517. The argstrng pointer returned by CreateArgstring()is installed in the
  8518.  
  8519. appropriate parameter slot of the message package:ARGO for the command string
  8520.  
  8521. or function name,and ARG1-ARG15 for argument strings. Argstrings can be
  8522.  
  8523. recycled after a packet has returned by calling the DeleteArgstring() function.
  8524.  
  8525.  
  8526.  
  8527. SENDING THE PACKET. Once the required fields have been filled in,the host
  8528.  
  8529. application can send the packet to the "REXX" public port using the EXEC
  8530.  
  8531. function PutMsg(). The address of the "REXX" port can be obtained by a call to
  8532.  
  8533. the FindPort()function,but this address should not be cached internally,since
  8534.  
  8535. the port could close at any time. To be absolutely safe,the calls to FindPort()
  8536.  
  8537. and PutMsg()should be bracketed by calls to the EXEC routines Forbid()and
  8538.  
  8539. Permit(). This will exclude the slight possibility that the message port could
  8540.  
  8541. close in the few microseconds before the message packet is actually sent to the
  8542.  
  8543. port address.
  8544.  
  8545.  
  8546.  
  8547. After sending the packet the host can return to its normal processing,since the
  8548.  
  8549. macro program will execute as a separate task. In most cases it will be
  8550.  
  8551. advisable to "lock-out" further user commands while the ARexx program is
  8552.  
  8553. running,to preserve te integrity of any shared data structures that may be
  8554.  
  8555. accessed externally.
  8556.  
  8557.  
  8558.  
  8559. COMMAND INVOCATIONS
  8560.  
  8561.  
  8562.  
  8563. In the command mode of invocation the host supplies a command string consisting
  8564.  
  8565. of a name token followed by an argument string. ARexx parses the string to
  8566.  
  8567. extract the command name,which is usually the name of a program file. The
  8568.  
  8569. default action is to use the remainder of the command string as the(single)
  8570.  
  8571. argument string for the program. This may be overridden by requesting command
  8572.  
  8573. tokenization,which is done by setting the RXFB_TOKEN modifier flag in the
  8574.  
  8575. action code of the message packet. In this case the entire command string will
  8576.  
  8577. be parsed,and the program may have many argument strings.(There is no limit to
  8578.  
  8579. the number of arguments that may be derived from the command string,since they
  8580.  
  8581. don't have to fit into the parameter slots of the message packet.)
  8582.  
  8583.  
  8584.  
  8585. The parsing process uses "white space" (blanks,tabs,etc.)as the token
  8586.  
  8587. separators,and has a several special features.
  8588.  
  8589.  
  8590.  
  8591. QUOTING CONVENTION. Either single(')or double(")quotes may be used to surround
  8592.  
  8593. items that include "white space" and would otherwise be separated during
  8594.  
  8595. parsing. Single quotes may appear within a double-quote-delimited token,and
  8596.  
  8597. vice versa;however,double-delimiter sequences are not accepted. The quotes are
  8598.  
  8599. removed from the parsed token. An "implicit" quote at the end of the string is
  8600.  
  8601. also recognized. If the command string ends before the closing delimiter has
  8602.  
  8603. been found,the null byte is accepted as the final delimiter. For example,
  8604.  
  8605.         look.rexx "Now is the time" "can't you see"
  8606.  
  8607.  
  8608.  
  8609. is a command with the two arguments strings "Now is the time" and "can't you
  8610.  
  8611. see"(but without the quotes.)
  8612.  
  8613.  
  8614.  
  8615. STRING FILES. If the command name(the first token of the string)is quoted,it is
  8616.  
  8617. assumed to be a "string file" --an ARexx program in a string,rather than the
  8618.  
  8619. name of a disk file. This is a convenient way to run very brief programs,
  8620.  
  8621. although programs of any length may be stored this way. If command tokenization
  8622.  
  8623. has not been specified,the remainder of the string is not scanned and no quote
  8624.  
  8625. characters are removed. In this case the quoting convention isuseful only for
  8626.  
  8627. indicating "string file" programs. The entire command string can be declared as
  8628.  
  8629. a "string file" by setting the RXFB_STRING modifier flag of the action code.
  8630.  
  8631. When this flag is set,no parsing at all is applied to the command.
  8632.  
  8633.  
  8634.  
  8635. RESULT STRING. Command invocations do not usually request a result string,but
  8636.  
  8637. can do so by setting the RXFB_RESULT modifier flag. The host application must
  8638.  
  8639. be prepared to recycle the returned result string once it is no longer needed.
  8640.  
  8641.  
  8642.  
  8643.                                 94
  8644.  
  8645.  
  8646.  
  8647. FUNCTION INVOCATIONS
  8648.  
  8649.  
  8650.  
  8651. In a function invocation the host application supplies a function name string
  8652.  
  8653. and from 0 to 15 argument strings. The name string is used to locate an
  8654.  
  8655. external program file and may include directory specifiers and a file
  8656.  
  8657. extension. The actual argument count(not including the name string)must be
  8658.  
  8659. placed in the low-order byte of the command code.
  8660.  
  8661.  
  8662.  
  8663. This mode of invocation is normally used when a result string is expected and
  8664.  
  8665. the argument strings are conveniently available. Note that a result does not
  8666.  
  8667. have to be requested,however.
  8668.  
  8669.  
  8670.  
  8671. RESULT STRINGS. Function invocations request a result string by setting the
  8672.  
  8673. RXFB_RESULT modifier flag bit. If no errors occurred and a result string was
  8674.  
  8675. requested,the secondary result field in the returned packet will be a pointer
  8676.  
  8677. to the result string. However,if the program exited without supplying a result,
  8678.  
  8679. the secondary field will be zero.
  8680.  
  8681.  
  8682.  
  8683. STRING FILES. The function name argument may specify a "string file" rather
  8684.  
  8685. than the name of a filing system object. This is indicated by setting the
  8686.  
  8687. RXFB_STRING modifier flag.
  8688.  
  8689.  
  8690.  
  8691. SEARCH ORDER
  8692.  
  8693.  
  8694.  
  8695. The search for a program file matching a command or function name is normaly a
  8696.  
  8697. two-step process. For each directory to be checked,a search is made first with
  8698.  
  8699. the current file extension appended to the name string. If this search fails,
  8700.  
  8701. the second search uses the unmodified name string. The first step is skipped if
  8702.  
  8703. the command or function name includes an explicit file extension.
  8704.  
  8705.  
  8706.  
  8707. The default file extension is ".rexx,"but this can be changed by supplying a
  8708.  
  8709. file extension string in an extended message packet. Host applications will
  8710.  
  8711. usually specify a file extension,since it provides a convenient way to
  8712.  
  8713. distinguish the macro programs that are specific to that application. Refer to
  8714.  
  8715. the section on Extension Fields for further details.
  8716.  
  8717.  
  8718.  
  8719. The search path for a program depends on the way the program name was
  8720.  
  8721. specified. If an explicit device or directory specification precedes the
  8722.  
  8723. program name,only that directory will be searched. For example,the command-
  8724.  
  8725. level invocation of "rx df0:s/test" will search only the df0:s directory for a
  8726.  
  8727. file named test.rexx or test. If the program name does not include a path,the
  8728.  
  8729. search path begins with the current directory and proceeds to the system REXX:
  8730.  
  8731. directory. To further the above example,invoking the program as "rx test 1 2 3"
  8732.  
  8733. would search for the files test.rexx,test,REXX:test.rexx,and REXX:test,in that
  8734.  
  8735. order.
  8736.  
  8737.  
  8738.  
  8739. If an ARexx program cannot be found,one alternative action may be taken. If the
  8740.  
  8741. rm_PassPort field of an extended packet was supplied,the message packet is
  8742.  
  8743. passed along to that port,which might be the next process in a search chain.
  8744.  
  8745. Otherwise the message is returned with a "Program not found"error indication
  8746.  
  8747. (error code 1.)
  8748.  
  8749.  
  8750.  
  8751.                                 95
  8752.  
  8753.  
  8754.  
  8755. EXTENSION FIELDS
  8756.  
  8757.  
  8758.  
  8759. The RexxMsg structure includes several "extension fields" that can be used to
  8760.  
  8761. override various defaults when a program is invoked. These extension fields can
  8762.  
  8763. be filled in selectively,and only the non-zero values will override the
  8764.  
  8765. corresponding default. ARexx never modifies the extension area.
  8766.  
  8767.  
  8768.  
  8769. Host applications should supply values for the file extension and host address
  8770.  
  8771. fields of the message packet. The file extension affects which program files
  8772.  
  8773. will match a given command name,and allows macro programs specific to the host
  8774.  
  8775. to be given distinctive names. The host address must refer to a public message
  8776.  
  8777. port,and will usually indicate the host's own port. Any appropriate(but usually
  8778.  
  8779. short)strings can be chosen for these values. Oftern,the name of the
  8780.  
  8781. applications program itself can be used as its host address and file extension.
  8782.  
  8783.  
  8784.  
  8785. PASSPORT. The rm_PassPort field allows the search for a program to be "passed
  8786.  
  8787. along" to another messsage port after checking for an ARexx program. If the
  8788.  
  8789. command or function name doesn't resolve to an ARexx program,the message packet
  8790.  
  8791. is forwarded to the message port specified as the PassPort. This allows
  8792.  
  8793. applications to maintain control over the search order for external program
  8794.  
  8795. files.
  8796.  
  8797.  
  8798.  
  8799. Note that the rm_PassPort field must be the actual address of a message port,
  8800.  
  8801. rather than a name string. The PassPort therefore does not have a public port,
  8802.  
  8803. but the port should be a secured resource,since the message is sent directly to
  8804.  
  8805. this address without checking to see whether it is a valid message port.
  8806.  
  8807.  
  8808.  
  8809. HOST ADDRESS. The rm_ComAddr field overrides the default initial host address,
  8810.  
  8811. which is "REXX." The host address is the name of the messsage port to which
  8812.  
  8813. commands will be directed,and is supplied as a pointer to a null-terminated
  8814.  
  8815. string. Applications that support multiple instances of user data will usually
  8816.  
  8817. create a separate message port for each instance. The name of this port would
  8818.  
  8819. then be supplied as the host address for any commands issued from that
  8820.  
  8821. instance.
  8822.  
  8823.  
  8824.  
  8825. FILE EXTENSION. The rm_FileExt field is used to override the default file
  8826.  
  8827. extension for ARexx programs,which is "REXX". Host applications can use the
  8828.  
  8829. file extension to distinguish the names of the macro programs specific to that
  8830.  
  8831. application. It is supplied as a pointer to a null-terminated string.
  8832.  
  8833.  
  8834.  
  8835. INPUT AND OUTPUT STREAMS. The default input and output steams for an ARexx
  8836.  
  8837. program are inherited from the host application's process structure,if the host
  8838.  
  8839. is a process rather than just a task. One or both of these streams may be
  8840.  
  8841. overridden by supplying an appropriate value in the rm-Stdin or rm_stdout
  8842.  
  8843. fields. The values supplied must be valid DOS filehandles,and must not be
  8844.  
  8845. closed while the program is executing. The steams are installed directly into
  8846.  
  8847. the program's process structure,replacing the prior values.
  8848.  
  8849.  
  8850.  
  8851. The output stream is also used as the default tracing stream for the program.
  8852.  
  8853. If interactive tracing is to be used in a program,the output stream should
  8854.  
  8855. refer to a console device,since it will be used for input as well.
  8856.  
  8857.  
  8858.  
  8859.                                 96
  8860.  
  8861.  
  8862.  
  8863. In the event than an ARexx program is invoked by an EXEC task,rather than by an
  8864.  
  8865. DOS process,the extension field streams are the only way that the launched
  8866.  
  8867. program can be given default I/O streams.
  8868.  
  8869.  
  8870.  
  8871. INTERPRETING THE RESULT FIELDS
  8872.  
  8873.  
  8874.  
  8875. The message packet that invoked an ARexx program is returned to the client when
  8876.  
  8877. the program finishes. The two result fields will contain error codes or
  8878.  
  8879. possibly a result string. The interpretation of the result fields depends
  8880.  
  8881. partly on the mode of invocation. If the primary result field rm_Result1 is
  8882.  
  8883. zero,the program executed normally and the secondary field rm_Result2 will
  8884.  
  8885. contain a pointer to a result string,assuming that one was requested(and
  8886.  
  8887. available.)
  8888.  
  8889.  
  8890.  
  8891. If the primary result is non-zero,it represents either an error severity level
  8892.  
  8893. or else the return code from a command invocation. The two cases can be
  8894.  
  8895. distinguished by examining the secondary result. If the secondary field is also
  8896.  
  8897. non-zero,an error occurred and the secondary field is an ARexx error code. If
  8898.  
  8899. the secondary result is zero,then the primary result is the return code passed
  8900.  
  8901. by an "EXIT rc" or "RETURN rc" instruction in the program. The application
  8902.  
  8903. program can use this return code either as an error indication or to initiate
  8904.  
  8905. some particular processing action.
  8906.  
  8907.  
  8908.  
  8909. Result strings are always returned as an argstring and become the property(that
  8910.  
  8911. is,responsibility)of the host. When the string is no longer needed,it can be
  8912.  
  8913. released using the DelArgstring() function.
  8914.  
  8915.  
  8916.  
  8917. Errors occurring in macro programs should usually be reported to the user.
  8918.  
  8919. Explanatory messages are available for all ARexx error codes,and can be
  8920.  
  8921. obtained by calling the ARexx Systems Library function ErrorMsg().
  8922.  
  8923.  
  8924.  
  8925. COMMUNICATING WITH THE RESIDENT PROCESS
  8926.  
  8927.  
  8928.  
  8929. All communications with the resident process are handled by passing message
  8930.  
  8931. packets,which were previously diagrammed in Table 10.2. The packet has a
  8932.  
  8933. command field that describes the action to be performed and parameter fields
  8934.  
  8935. that are specific to the command. Message packets are processed as they are
  8936.  
  8937. received,and are then either returned to the sender or passed along to another
  8938.  
  8939. process(in the case of a program invocation.) The packet includes two result
  8940.  
  8941. fields that are used to return error codes or result strings. The parameter
  8942.  
  8943. fields of the message packet may contain either(long)integer values or pointers
  8944.  
  8945. to argument strings. String arguments are assumed to be argstring pointers
  8946.  
  8947. unless otherwise specified.
  8948.  
  8949.  
  8950.  
  8951. COMMAND(ACTION)CODES
  8952.  
  8953.  
  8954.  
  8955. The command codes that are currently implemented in the resident process are
  8956.  
  8957. described below. Commands are listed by their mnemonic codes,followed by the
  8958.  
  8959. valid modifier flags. The final code value is always the logical OR of the code
  8960.  
  8961. value and all of the modifier flags selected. The command code is installed in
  8962.  
  8963. the rm_Action field of the message packet.
  8964.  
  8965.  
  8966.  
  8967. USAGE: RXADDCON [RXFB_NONRET]
  8968.  
  8969. This code specifies an entry to be added to the Clip List. Parameter slot ARGO
  8970.  
  8971. points to the name string,slot ARG1 points to the value string,and slot ARG2
  8972.  
  8973. contains the length of the value string.
  8974.  
  8975.  
  8976.  
  8977.                                 97
  8978.  
  8979.  
  8980.  
  8981. The name and value arguments do not need to be argstrings,but can be just
  8982.  
  8983. pointers to storage areas. The name should be a null-terminated string,but the
  8984.  
  8985. value can contain arbitrary data including nulls.
  8986.  
  8987.  
  8988.  
  8989. USAGE: RXADDFH [RSFB_NONRET]
  8990.  
  8991. This action code specifies a function host to be added to the Library List.
  8992.  
  8993. Parameter slot ARGO points to the(null-terminated)host name string,and slot
  8994.  
  8995. ARG1 holds the search priority for the node. The search priority should be an
  8996.  
  8997. integer between 100 and -100 inclusive;the remaining priority ranges are
  8998.  
  8999. reserved for future extensions. If a none already exists with the same name,the
  9000.  
  9001. packet is returned with a warning level error code. Note that no test is made
  9002.  
  9003. at this time as to whether the host port exists.
  9004.  
  9005.  
  9006.  
  9007. USAGE:RXADDLIB [RXFB_NONRET]
  9008.  
  9009. This code specifies an entry to be added to the Library List. Parameter slot
  9010.  
  9011. ARGO points to a null-terminated name string referring either to a function
  9012.  
  9013. library or a function host. Slot ARG1 is the priority for the node and should
  9014.  
  9015. be an integer between 100 and -100 inclusive;the remaining priority ranges are
  9016.  
  9017. reserved for future extensions. Slot ARG2 contains the entry oint offset and
  9018.  
  9019. slot ARG3 is the library version number. If a node already exists with the same
  9020.  
  9021. name,the packet is returned with a warning level error code. Otherwise,a new
  9022.  
  9023. entry is added and the library or host becomes available to ARexx programs.
  9024.  
  9025. Note that no test is made at this time as to whether the library exists and can
  9026.  
  9027. be opened.
  9028.  
  9029.  
  9030.  
  9031. USAGE:RXCOMM [RXFB_TOKEN] [RXFB_STRING] [RXFB_RESULT] [RXFB_NOIO]
  9032.  
  9033. Specifies a command-mode invocation of an ARexx program. Parameter slot ARGO
  9034.  
  9035. must contain an argstring ointer to the command string. The RXFB_TOKEN flag
  9036.  
  9037. specifies that the command line is to be tokenized before being passed to the
  9038.  
  9039. invoked program. The RXFB_STRING flag bit indicates that the command string is
  9040.  
  9041. a "string file." Command invocations do not normally return result strings,but
  9042.  
  9043. the RXFB_RESULT flag can be set if the caller is prepared to handle the cleanup
  9044.  
  9045. associated with a returned string. The RXFB_NOIO modifier suppresses the
  9046.  
  9047. inheritance of the host's input and output streams.
  9048.  
  9049.  
  9050.  
  9051. USAGE:RXFUNC [RXFB_RESULT] [RXFB_STRING] [RXFB_NOIO] argcount
  9052.  
  9053. This command code specifies a function invoction. Parameter slot ARGO contains
  9054.  
  9055. a pointer to the function name string,and slots ARG1 through ARG15 point to the
  9056.  
  9057. argument strings,all of which must be passed as argstrings. The lower byte of
  9058.  
  9059. the command code is the argument count;this count excludes the function name
  9060.  
  9061. string itself. Function calls normally set the RXFB_RESULT flag,but this is not
  9062.  
  9063. mandatory. The RXFB_STRING modifier indicates that the function name string is
  9064.  
  9065. actually a "string file". The RXFB_NOIO modifier suppresses the inheritance of
  9066.  
  9067. the host's input and output streams.
  9068.  
  9069.  
  9070.  
  9071. USAGE:RXREMCON [RXFB_NONRET]
  9072.  
  9073. This code requests that an entry be removed from the Clip List. Parameter slot
  9074.  
  9075. ARGO points to the null-terminated name to be removed. The Clip List is
  9076.  
  9077. searched for a node matching the supplied name,and if a match is found the list
  9078.  
  9079. node is removed and recycled. If no match is found the packet is returned with
  9080.  
  9081. a warning error code.
  9082.  
  9083.  
  9084.  
  9085. USAGE:RXREMLIB [RXFB_NONRET]
  9086.  
  9087. This command removes a Library List entry. Parameter slot ARGO points to the
  9088.  
  9089. null terminated string specifying the library to be removed. The Library List
  9090.  
  9091. is searched for a node matching the library name,and if a match is found the
  9092.  
  9093.  
  9094.  
  9095.                                 98
  9096.  
  9097.  
  9098.  
  9099. node is removed and released. If no match is found the packet is returned with
  9100.  
  9101. a warning error code. The libary node will not be removed if the library is
  9102.  
  9103. currently being used by an ARexx program.
  9104.  
  9105.  
  9106.  
  9107. USAGE:RXTCCLS [RXFB_NONRET]
  9108.  
  9109. This code requests that the global tracing console be closed. The console
  9110.  
  9111. window will be closed immediately unless one or more ARexx programs are waiting
  9112.  
  9113. for input from the console. In this event,the window will be closed as soon as
  9114.  
  9115. the active programs are no longer using it.
  9116.  
  9117.  
  9118.  
  9119. USAGE:RXTCOPN [RXFB_NONRET]
  9120.  
  9121. This command requests that the global tracing console be opened. Once the
  9122.  
  9123. console is open,all active ARexx programs will divert their tracing output to
  9124.  
  9125. the console. Tracing input(for interactive debugging)will also be diverted to
  9126.  
  9127. the new console. Only one console can be opened;subsequent RXTCOPN requests
  9128.  
  9129. will be returned with a warning error message.
  9130.  
  9131.  
  9132.  
  9133. MODIFIER FLAGS
  9134.  
  9135.  
  9136.  
  9137. Command codes may include modifier flags to select various processing options.
  9138.  
  9139. Modifier flags are specific to certain commands,and are ignored otherwise.
  9140.  
  9141.  
  9142.  
  9143. RXFB_NOIO. This modifier is used with the RXCOMM and RXFUNC command codes to
  9144.  
  9145. suppress the automatic inheritance of the host's input and output streams.
  9146.  
  9147.  
  9148.  
  9149. RXFB_NONRET. Specifies that the message packet is to be recycled by the
  9150.  
  9151. resident process rather than being returned to the sender. This implies that
  9152.  
  9153. the sender doesn't care about whether the requested action succeeded,since the
  9154.  
  9155. returned packet provides the only means of acknowledgement. Messge packets are
  9156.  
  9157. released using the library function DeleteRexxMsg().
  9158.  
  9159.  
  9160.  
  9161. RXFB_RESULT. This modifer is valid with the RXCOMM and RXFUNC commands,and
  9162.  
  9163. requests that the called program return a result string. If the program
  9164.  
  9165. EXITs(or RETURNs)with an expression,the expression result is returned to the
  9166.  
  9167. caller as an argstring. It is then the caller's responsibility to release the
  9168.  
  9169. argstring when it is no longer needed;this can be done using the library
  9170.  
  9171. function DeleteArgstring().
  9172.  
  9173.  
  9174.  
  9175. RXFB_STRING. This modifer is valid with the RXCOMM and RXFUNC command codes. It
  9176.  
  9177. indicates that the command or function argument(in slot ARGO)is a "string file"
  9178.  
  9179. rahter than a file name.
  9180.  
  9181.  
  9182.  
  9183. RXFB_TOKEN. This flag is used with the RXCOMM code to request that the command
  9184.  
  9185. string be completely tokenized before being passed to the invoked program.
  9186.  
  9187. Programs invoked as commands normally have only a single argument string. The
  9188.  
  9189. tokenization process uses "white space" to separate the tokens,except within
  9190.  
  9191. quoted strings. Quoted strings can use either single or double quotes,and the
  9192.  
  9193. end of the command string(a null character)is considered as an implicit closing
  9194.  
  9195. quote.
  9196.  
  9197.  
  9198.  
  9199.                                 99
  9200.  
  9201.  
  9202.  
  9203. RESULT FIELDS
  9204.  
  9205.  
  9206.  
  9207. The resident process uses the standard command-level conventions for the
  9208.  
  9209. primary return code installed in rm_Result1. Minor or warning errors are
  9210.  
  9211. indicated by a value of 5,and more serious errors are returned as values of 10
  9212.  
  9213. or 20. The secondary result field rm-Result2 will either be zero or an ARexx
  9214.  
  9215. error code if applicable.
  9216.  
  9217.  
  9218.  
  9219. Note that RXCOMM and RXFUNC messages are returned directly by the invoked macro
  9220.  
  9221. program,rathe than by the residen process.
  9222.  
  9223.  
  9224.  
  9225. EXTERNAL FUNCTION LIBRARIES
  9226.  
  9227.  
  9228.  
  9229. ARexx supports external function libraries as a mechanism for user-defined
  9230.  
  9231. extensions to the language. Function libraries may be written and maintained by
  9232.  
  9233. users or applications developers.
  9234.  
  9235.  
  9236.  
  9237. Regardless of the intended application,all function libraries share a common
  9238.  
  9239. structure. The initial design follows that of the standard EXEC shared library,
  9240.  
  9241. with the three required entry points Open,Close,and Expunge,plus a reserved
  9242.  
  9243. slot. The library must also have a "query" entry point,which serves to match
  9244.  
  9245. the name supplied by ARexx with the intended function. Typically,this will
  9246.  
  9247. consist of a table of function names and a routine to search for the specified
  9248.  
  9249. one.
  9250.  
  9251.  
  9252.  
  9253. REENTRANCY. Functions libraries should be designed to be fully reentrant,since
  9254.  
  9255. any number of ARexx programs may be running at any time. If this is not
  9256.  
  9257. feasible due to other design constraints,the query function should include a
  9258.  
  9259. lockout mechanism to prevent multiple calls to the library routines.
  9260.  
  9261.  
  9262.  
  9263.                                 100
  9264.  
  9265.  
  9266.  
  9267. CALLING CONVENTION
  9268.  
  9269.  
  9270.  
  9271. The library's query function will be called from the interpreter's context with
  9272.  
  9273. the address of a message packet in register A0 and the library base in A6. The
  9274.  
  9275. structure of the message packet is the same as that in Table 10.2,but note that
  9276.  
  9277. although a message packet is used to carry the arguments,it is not queued at a
  9278.  
  9279. message port and does not need to be unlinked. The name of the function to be
  9280.  
  9281. called is carried in the ARGO parameter slot. The query function must search
  9282.  
  9283. for this function name and,if the name cannot be found,must return an error
  9284.  
  9285. code of 1("Program not found")in register D0. The library will then be closed
  9286.  
  9287. and the search continued in the next function library. The query function
  9288.  
  9289. should not modify any fields within the message packet,as it must be passed
  9290.  
  9291. along to the next library until the function is located.
  9292.  
  9293.  
  9294.  
  9295. PARAMETER CONVERSION
  9296.  
  9297.  
  9298.  
  9299. Once the requested function has been found,the query funcion may need to
  9300.  
  9301. transform the parameters passed by ARexx into the form expected by the
  9302.  
  9303. function. Whether the parameter strings need to be converted depends on how
  9304.  
  9305. they are to be used. In some cases it may be sufficient just to foward a
  9306.  
  9307. pointer to the message packet to the called function,while in other cases the
  9308.  
  9309. query function may need to load parameters into registers or to perform
  9310.  
  9311. conversion operations. The parameters in ARG1-ARG15 are always passed as
  9312.  
  9313. argstrings,and may be treated like a pointer to a null-terminated string.
  9314.  
  9315. Further attributes are stored at negative offsets from the argstring pointer,
  9316.  
  9317. and may be helpful in working with the string.
  9318.  
  9319.  
  9320.  
  9321. Numeric quantities are passed as strings of ASCII characters and will need to
  9322.  
  9323. be converted to integer or floating-point format if arithmetic calculations are
  9324.  
  9325. to be performed. The ARexx System Library includes a limited set of functions
  9326.  
  9327. to do parameter conversions.
  9328.  
  9329.  
  9330.  
  9331. The actual parameter count can be obtained from the low-order byte of the
  9332.  
  9333. rm_Action field in the message packet. The count never includes the function
  9334.  
  9335. name itself(in ARGO),but does include arguments specified as "defaults." Such
  9336.  
  9337. arguments will have a zero value in the corresponding parameter slot.
  9338.  
  9339.  
  9340.  
  9341. Note that the parameter block of the message packet,containing the fields
  9342.  
  9343. ARG0-ARG15,is structured like the argument array expected by the main(argc,
  9344.  
  9345. argv)function of a "C" program. This suggests a simple way that a function
  9346.  
  9347. library could provide a bridge to a series of "C" programs. The query function
  9348.  
  9349. would need only to determine the address of the called function,and then push
  9350.  
  9351. the parameter block address and argument count onto the program stack.
  9352.  
  9353.  
  9354.  
  9355. RETURNED VALUES
  9356.  
  9357.  
  9358.  
  9359. Each library function must return an error code and a value string. The error
  9360.  
  9361. code is returned in register D0,and should be 0 if no errors occurred. The
  9362.  
  9363. value string must be returned as an argstring pointer in register A1,unless D0
  9364.  
  9365. indicates that an error occurred during the call. The mechanisms for creating
  9366.  
  9367. the proper return values can be made part of the query function,so that all
  9368.  
  9369. functions in the library share a common return path.
  9370.  
  9371.  
  9372.  
  9373.                                 101
  9374.  
  9375.  
  9376.  
  9377. DIRECT MANIPULATION OF DATA STRUCTURES
  9378.  
  9379.  
  9380.  
  9381. All of the data structures maintained by the resident process are built into
  9382.  
  9383. the ARexx Systems Library base and are therefore accessible to external
  9384.  
  9385. programs. The Task List in the RexxBase structure links the global data
  9386.  
  9387. structures for all currently active ARexx programs. This linkage uses the node
  9388.  
  9389. contained in the message port of the RexxTask structure,rather than at the head
  9390.  
  9391. of the structure. The RexxTask structure is the global data structure and
  9392.  
  9393. initial storage environment for the ARexx program,and all descendant storage
  9394.  
  9395. environments are linked into the Environment List. The linkage of internal data
  9396.  
  9397. structures is such that the complete internal state of all ARexx programs can
  9398.  
  9399. be reached starting from the library base pointer.
  9400.  
  9401.  
  9402.  
  9403. Two library functions,LockRexxBase() and UnlockRexxBase(),are provided to
  9404.  
  9405. mediate access to the global structures. The structure base should be locked
  9406.  
  9407. before reading any of the data items or traversing any of the lists. The
  9408.  
  9409. present version of these functions provides only a global lock,but future
  9410.  
  9411. extensions will allow individual resources to be locked.
  9412.  
  9413.  
  9414.  
  9415. In general it should not be necessary to manipulate directly any of these data
  9416.  
  9417. structures. Functions have been provided in the ARexx Systems Library to
  9418.  
  9419. perform all of the operations required to interface external program to the
  9420.  
  9421. ARexx system. It is therefore recommended that applictions developers avoid
  9422.  
  9423. using any of the internal structures except as provided through the library
  9424.  
  9425. functions.
  9426.  
  9427.  
  9428.  
  9429.                                 102
  9430.  
  9431.  
  9432.  
  9433.                         APPENDIX A ERROR MESSAGES
  9434.  
  9435.  
  9436.  
  9437. When the ARexx interpeter detects an error in a program,it returns an error
  9438.  
  9439. code to indicate the nature of the problem. Errors are normally handled by
  9440.  
  9441. displaying the error code,the source line number where the error occurred,and a
  9442.  
  9443. brief message explaining the error condition. Unless the SYNTAX interrupt has
  9444.  
  9445. been previously enabled(using the SIGNAL instruction),the program then
  9446.  
  9447. terminates and control returns to the caller. Most syntax and execution errors
  9448.  
  9449. can be trapped by the SYNTAX interrupt,allowing the user to retain control and
  9450.  
  9451. perform whatever special error processing is required. Certain errors are
  9452.  
  9453. generated outside of the context of an ARexx program,and therefore cannot be
  9454.  
  9455. trapped by this mechanism. Refer to chapter 7 for further information on error
  9456.  
  9457. trapping and processing.
  9458.  
  9459.  
  9460.  
  9461. Associated with each error code is a severity level that is reported to the
  9462.  
  9463. calling program as the primary result code. The error code itself is returned
  9464.  
  9465. as the secondary result. The subsequent propagation or reporting of these codes
  9466.  
  9467. is of course dependent on the external(calling)program.
  9468.  
  9469.  
  9470.  
  9471. The following pages list all of the currently-defined error codes,along with
  9472.  
  9473. the associated severity level and message string.
  9474.  
  9475.  
  9476.  
  9477. ERROR: 1 SEVERITY: 5 MESSGE: PROGRAM NOT FOUND
  9478.  
  9479. The named program could not be found,or was not an ARexx program. ARexx
  9480.  
  9481. programs are expected to start with a "/*" sequence. This error is detected by
  9482.  
  9483. the external interface and cannot be trapped by the SYNTAX interrupt.
  9484.  
  9485.  
  9486.  
  9487. ERROR: 2 SEVERITY: 10 MESSAGE: EXECUTION HALTED
  9488.  
  9489. A control-C break or an external half request was received and the program
  9490.  
  9491. terminated. This error will be trapped if the HALT interrupt has been enabled.
  9492.  
  9493.  
  9494.  
  9495. ERROR: 3 SEVERITY: 20 MESSAGE: INSUFFICIENT MEMORY
  9496.  
  9497. The interpreter was unable to allocate enough memory for an operation. Since
  9498.  
  9499. memory space is required for all parsing and execution operations,this error
  9500.  
  9501. cannot usually be trapped by the SYNTAX interrupt.
  9502.  
  9503.  
  9504.  
  9505. ERROR: 4 SEVERITY: 10 MESSAGE: INVALID CHARACTER
  9506.  
  9507. A non-ASCII character was found in the program. Control codes and other non-
  9508.  
  9509. ASCII characters may be used in a program by defining them as hex or binary
  9510.  
  9511. strings. This is a scan phase error and cannot be trapped by the SYNTAX
  9512.  
  9513. interrupt.
  9514.  
  9515.  
  9516.  
  9517. ERROR: 5 SEVERITY: 10 MESSAGE: UNMATCHED QUOTE
  9518.  
  9519. A closing single or double quote was missing. Check that each string is
  9520.  
  9521. properly delimited. This is a scan phase error and cannot be trapped by the
  9522.  
  9523. SYNTAX interrupt.
  9524.  
  9525.  
  9526.  
  9527.                                 103
  9528.  
  9529.  
  9530.  
  9531. ERROR: 6 SEVERITY: 10 MESSAGE: UNTERMINATED COMMENT
  9532.  
  9533. The closing "*/" for a comment field was not found. Remember that comments may
  9534.  
  9535. be nested,so each "/*" must be matched by a "*/." This is a scan phase error
  9536.  
  9537. and cannot be trapped by the SYNTAX interrupt.
  9538.  
  9539.  
  9540.  
  9541. ERROR: 7 SEVERITY: 10 MESSAGE: CLAUSE TOO LONG
  9542.  
  9543. A clause was too long for the internal buffer used as temporary storage. The
  9544.  
  9545. source line in question should be broken into smaller parts. This is a scan
  9546.  
  9547. phase error and cannot be trapped by the SYNTAX interrupt.
  9548.  
  9549.  
  9550.  
  9551. ERROR: 8 SEVERITY: 10 MESSAGE: INVALID TOKEN
  9552.  
  9553. An unrecognized lexical token was found,or a clause could not be properly
  9554.  
  9555. classified. This is a scan phase error and cannot be trapped by the SYNTAX
  9556.  
  9557. interrupt.
  9558.  
  9559.  
  9560.  
  9561. ERROR: 9 SEVERITY: 10 MESSAGE: SYMBOL OR STRING TOO LONG
  9562.  
  9563. An attempt was made to create a string longer than the maximum supported by the
  9564.  
  9565. interpreter. The implementation limits for internal structure are given in
  9566.  
  9567. Appendix B.
  9568.  
  9569.  
  9570.  
  9571. ERROR: 10 SEVERITY: 10 MESSAGE: INVALID MESSAGE PACKET
  9572.  
  9573. An invalid action code was found in a message packet sent to the ARexx resident
  9574.  
  9575. process. The packet was returned without being processed. This error is
  9576.  
  9577. detected by the external interface and cannot be trapped by the SYNTAX
  9578.  
  9579. interrupt.
  9580.  
  9581.  
  9582.  
  9583. ERROR: 11 SEVERITY: 10 MESSAGE: COMMAND STRING ERROR
  9584.  
  9585. A command string could not be processed. This error is detected by the external
  9586.  
  9587. interface and cannot be trapped by the SYNTAX interrupt.
  9588.  
  9589.  
  9590.  
  9591. ERROR: 12 SEVERITY: 10 MESSAGE: ERROR RETURN FROM FUNCTION
  9592.  
  9593. An external function returned a non-zero error code. Check that the correct
  9594.  
  9595. parameters were supplied to the function.
  9596.  
  9597.  
  9598.  
  9599. ERROR: 13 SEVERITY: 10 MESSAGE: HOST ENVIRONMENT NOT FOUND
  9600.  
  9601. The message port corresponding to a host address string could not be found.
  9602.  
  9603. Check that the required external host is active.
  9604.  
  9605.  
  9606.  
  9607. ERROR: 14 SEVERITY: 10 MESSAGE: REQUESTED LIBRARY NOT FOUND
  9608.  
  9609. An attempt was made to open a function library included in the Library List,but
  9610.  
  9611. the library could not be opened. Check that the correct name and version of the
  9612.  
  9613. library were specified when the library was added to the resource list.
  9614.  
  9615.  
  9616.  
  9617. ERROR: 15 SEVERITY: 10 MESSGE: FUNCTION NOT FOUND
  9618.  
  9619. A function was called that could not be found in any of the currently
  9620.  
  9621. accessible libraries,and could not be located as an external program. Check
  9622.  
  9623. that the appropriate function libraries have been added to the Libraries List.
  9624.  
  9625.  
  9626.  
  9627.                                 104
  9628.  
  9629.  
  9630.  
  9631. ERROR: 16 SEVERITY: 10 MESSAGE: FUNCTION DID NOT RETURN VALUE
  9632.  
  9633. A function was called which failed to return a result string,but did not
  9634.  
  9635. otherwise report an error. Check that the function was programmed correctly,or
  9636.  
  9637. invoke it using the CALL instruction.
  9638.  
  9639.  
  9640.  
  9641. ERROR: 17 SEVERITY: 10 MESSAGE: WRONG NUMBER OF ARGUMENTS
  9642.  
  9643. A call was made to a function which expected more(or fewer)arguments. This
  9644.  
  9645. error will be generated if a Built-In or external function is called with more
  9646.  
  9647. arguments than can be accomodated in the message packet used for external
  9648.  
  9649. communications.
  9650.  
  9651.  
  9652.  
  9653. ERROR: 18 SEVERITY: 10 MESSAGE: INVALID ARGUMENT TO FUNCTION
  9654.  
  9655. An inappropriate argument was supplied to a function,or a required argument was
  9656.  
  9657. missing. Check the parameter requirements specified for the function.
  9658.  
  9659.  
  9660.  
  9661. ERROR: 19 SEVERITY: 10 MESSAGE: INVALID PROCEDURE
  9662.  
  9663. A PROCEDURE instruction was issued in an invalid context. Either no internal
  9664.  
  9665. functions were active,or a PROCEDURE had already been issued in the current
  9666.  
  9667. storage environment.
  9668.  
  9669.  
  9670.  
  9671. ERROR: 20 SEVERITY: 10 MESSAGE: UNEXPECTED THEN OR WHEN
  9672.  
  9673. A WHEN or THEN instruction was executed outside of a valid context. The WHEN
  9674.  
  9675. instruction is valid only within a SELECT range,and THEN must be the next
  9676.  
  9677. instruciton following an IF or WHEN.
  9678.  
  9679.  
  9680.  
  9681. ERROR: 21 SEVERITY: 10 MESSAGE: UNEXPECTED ELSE OR OTHERWISE
  9682.  
  9683. An ELSE or OTHERWISE was found outside of a valid context. The OTHERWISE
  9684.  
  9685. instruction is valid only within a SELECT range. ELSE is valid only following
  9686.  
  9687. the THEN branch of an IF range.
  9688.  
  9689.  
  9690.  
  9691. ERROR: 22 SEVERITY: 10 MESSAGE: UNEXPECTED BREAK,LEAVE,or ITERATE
  9692.  
  9693. The BREAK instruction is valid only within a DO range or inside an INTERPRETed
  9694.  
  9695. string. The LEAVE and ITERATE instuctions are valid only within an iterative DO
  9696.  
  9697. range.
  9698.  
  9699.  
  9700.  
  9701. ERROR: 23 SEVERITY: 10 MESSAGE: INVALID STATEMENT IN SELECT
  9702.  
  9703. A invalid statement was encountered within a SELECT range. Only WHEN,THEN,and
  9704.  
  9705. OTHERWISE statements are valid within a SELECT range,except for the conditional
  9706.  
  9707. statements following THEN or OTHERWISE clauses.
  9708.  
  9709.  
  9710.  
  9711. ERROR: 24 SEVERITY: 10 MESSAGE: MISSING OR MULTIPLE THEN
  9712.  
  9713. An expected THEN clause was not found,or another THEN was found after one had
  9714.  
  9715. already been executed.
  9716.  
  9717.  
  9718.  
  9719. ERROR: 25 SEVERITY: 10 MESSAGE: MISSING OTHERWISE
  9720.  
  9721. None of the WHEN clauses in a SELECT succeeded,but no OTHERWISE clause was
  9722.  
  9723. supplied.
  9724.  
  9725.  
  9726.  
  9727. ERROR: 26 SEVERITY: 10 MESSAGE: MISSING OR UNEXPECTED END
  9728.  
  9729. The program source ended before an END was found for a DO or SELECT instruction
  9730.  
  9731. or an END was encountered outside of a DO or SELECT range.
  9732.  
  9733.  
  9734.  
  9735.                                 105
  9736.  
  9737.  
  9738.  
  9739. ERROR: 27 SEVERITY: 10 MESSAGE: SYMBOL MISMATCH
  9740.  
  9741. The symbol specified on an END,ITERATE,or LEAVE instruction did not match the
  9742.  
  9743. index variable for the associated DO range. Check that the active loops have
  9744.  
  9745. been nested properly.
  9746.  
  9747.  
  9748.  
  9749. ERROR: 28 SEVERITY: 10 MESSAGE: INVALID DO SYNTAX
  9750.  
  9751. An invalid DO instruction was executed. An initializer expression must be given
  9752.  
  9753. if a TO or BY expression is specified,and a FOR expression must yield a non-
  9754.  
  9755. negative integer result.
  9756.  
  9757.  
  9758.  
  9759. ERROR: 29 SEVERITY: 10 MESSAGE: INCOMPLETE IF OR SELECT
  9760.  
  9761. An IF or SELECT range ended before all of the required statement were found.
  9762.  
  9763. Check whether the conditional statement following a THEN,ELSE,or OTHERWISE
  9764.  
  9765. clause was omitted.
  9766.  
  9767.  
  9768.  
  9769. ERROR: 30 SEVERITY: 10 MESSAGE: LABEL NOT FOUND
  9770.  
  9771. A label specified by a SIGNAL instruction,or implicitly referenced by an
  9772.  
  9773. enabled interrupt,could not be found in the program source. Labels defined
  9774.  
  9775. dynamically by an INTERPRET instruction or by interactive input are not
  9776.  
  9777. included in the search.
  9778.  
  9779.  
  9780.  
  9781. ERROR: 31 SEVERITY: 10 MESSAGE: SYMBOL EXPECTED
  9782.  
  9783. A non-symbol token was found where only a symbol token is valid. The DROP,END,
  9784.  
  9785. LEAVE,ITERATE,and UPPER instructions may only be followed by a symbol token,and
  9786.  
  9787. will generate this error if anything else is supplied. This message will also
  9788.  
  9789. be issued if a required symbol is missing.
  9790.  
  9791.  
  9792.  
  9793. ERROR: 32 SEVERITY: 10 MESSAGE: SYMBOL OR STRING EXPECTED
  9794.  
  9795. An invalid token was found in a context where only a symbol or string is valid.
  9796.  
  9797.  
  9798.  
  9799. ERROR: 33 SEVERITY: 10 MESSAGE: INVALID KEYWORD
  9800.  
  9801. A symbol token in an instruction clause was identified as a keyword,but was
  9802.  
  9803. invalid in the specific context.
  9804.  
  9805.  
  9806.  
  9807. ERROR: 34 SEVERITY: 10 MESSAGE: REQUIRED KEYWORD MISSING
  9808.  
  9809. An instuction clause required a specific keyword token to be present,but it was
  9810.  
  9811. not supplied. For example,this messge will be issued if a SIGNAL ON instruction
  9812.  
  9813. is not followed by one of the interrupt keywords(e.g.SYNTAX.)
  9814.  
  9815.  
  9816.  
  9817. ERROR: 35 SEVERITY: 10 MESSAGE: EXTRANEOUS CHARACTERS
  9818.  
  9819. A seemingly valid statement was executed,but extra characters were found at the
  9820.  
  9821. end of the clause.
  9822.  
  9823.  
  9824.  
  9825. ERROR: 36 SEVERITY: 10 MESSAGE: KEYWORD CONFLICT
  9826.  
  9827. Two mutually exclusive keywords were included in an instruction clause,or a
  9828.  
  9829. keyword was included twice in the same instruction.
  9830.  
  9831.  
  9832.  
  9833. ERROR: 37 SEVERITY: 10 MESSAGE INVALID TEMPLATE
  9834.  
  9835. The template provided with an ARG,PARSE,or PULL instruction was not properly
  9836.  
  9837. constructed. Refer to Chapter 8 for a description of template structure and
  9838.  
  9839. processing.
  9840.  
  9841.  
  9842.  
  9843.                                 106
  9844.  
  9845.  
  9846.  
  9847. ERROR: 38 SEVERITY: 10 MESSAGE: INVALID TRACE REQUEST
  9848.  
  9849. The alphabetic keyword supplied with a TRACE instruction or as the argument to
  9850.  
  9851. the TRACE()Built-In function was not valid. Refer to Chapter 7 for the valid
  9852.  
  9853. TRACE options.
  9854.  
  9855.  
  9856.  
  9857. ERROR: 39 SEVERITY: 10 MESSAGE: UNINITIALIZED VARIABLE
  9858.  
  9859. An attempt was made to use an uninitialized variable while the NOVALUE
  9860.  
  9861. interrupt was enabled.
  9862.  
  9863.  
  9864.  
  9865. ERROR: 40 SEVERITY: 10 MESSAGE: INVALID VARIABLE NAME
  9866.  
  9867. An attempt was made to assign a value to a fixed symbol.
  9868.  
  9869.  
  9870.  
  9871. ERROR: 41 SEVERITY: 10 MESSAGE: INVALID EXPRESSION
  9872.  
  9873. An error was detected during the evaluation an expression. Check that each
  9874.  
  9875. operator has the correct number of operands,and that no extraneous tokens
  9876.  
  9877. appear in the expression. This error will be detected only in expressions that
  9878.  
  9879. are actually evaluated. No checking is performed on expressions in clauses that
  9880.  
  9881. are being skipped.
  9882.  
  9883.  
  9884.  
  9885. ERROR: 42 SEVERITY: 10 MESSAGE: UNBALANCED PARENTHESE
  9886.  
  9887. An expression was found with an unequal number of opening and closing
  9888.  
  9889. parentheses.
  9890.  
  9891.  
  9892.  
  9893. ERROR: 43 SEVERITY: 43 MESSAGE: NESTING LIMIT EXCEEDED
  9894.  
  9895. The number of subexpressions in an expression was greater than the maximum
  9896.  
  9897. allowed. The expression should be simplified by breaking it into two or more
  9898.  
  9899. intermediate expressions.
  9900.  
  9901.  
  9902.  
  9903. ERROR: 44 SEVERITY: 10 MESSAGE: INVALID EXPRESSION RESULT
  9904.  
  9905. The result of an expression was not valid within its context. For example,this
  9906.  
  9907. messge will be issued if an increment or limit expression in a DO instruction
  9908.  
  9909. yields a non-numeric result.
  9910.  
  9911.  
  9912.  
  9913. ERROR: 45 SEVERITY: 10 MESSAGE: EXPRESSION REQUIRED
  9914.  
  9915. An expression was omitted in a context where one is required. For example,the
  9916.  
  9917. SIGNAL instruction,if not followed by the keywords ON or OFF,must be followed
  9918.  
  9919. by an expression.
  9920.  
  9921.  
  9922.  
  9923. ERROR: 46 SEVERITY: 10 MESSAGE: BOOLEAN VALUE NOT 0 OR 1
  9924.  
  9925. An expression result was expected to yield a boolean result,but evaluated to
  9926.  
  9927. something other than 0 or 1.
  9928.  
  9929.  
  9930.  
  9931. ERROR: 47 SEVERITY: 10 MESSAGE: ARITHMETIC CONVERSION ERROR
  9932.  
  9933. A non-numeric operand was used in a operation requiring numeric operands. This
  9934.  
  9935. message will also be generated by an invalid hex or binary string.
  9936.  
  9937.  
  9938.  
  9939. ERROR: 48 SEVERITY: 10 MESSAGE: INVALID OPERAND
  9940.  
  9941. An operand was not valid for the intended operation. This message will be
  9942.  
  9943. generated if an attempt is made to divide by 0,or if a fractional exponent is
  9944.  
  9945. used in an exponentiation operation.
  9946.  
  9947.  
  9948.  
  9949.                                 107
  9950.  
  9951.  
  9952.  
  9953.                 APPENDIX B LIMITS AND COMPATIBILITY
  9954.  
  9955.  
  9956.  
  9957. ARexx was designed to adhere closely to the REXX language standard. This
  9958.  
  9959. appendix discusses those areas where ARexx departs from the standard.
  9960.  
  9961.  
  9962.  
  9963. LIMITS
  9964.  
  9965.  
  9966.  
  9967. Language definitions seldom include predefined limits to the program structures
  9968.  
  9969. that can be created. Only a few such restrictions were imposed in implementing
  9970.  
  9971. ARexx,and most of the internal structure are limited only by the total amount
  9972.  
  9973. of memory available. The current implementation limits are listed below.
  9974.  
  9975.  
  9976.  
  9977. LENGTH OF STRINGS. Strings,symbol names,and value strings are limited to a
  9978.  
  9979. maximum length of 65,535 bytes.
  9980.  
  9981.  
  9982.  
  9983. LENGTH OF CLAUSES. Clauses are limited to a maximum of 800 characters after
  9984.  
  9985. removing comments and multiple blanks.
  9986.  
  9987.  
  9988.  
  9989. NODES IN COMPOUND NAMES. Compound symbol names may include a maximum of 50
  9990.  
  9991. nodes,including the stem.
  9992.  
  9993.  
  9994.  
  9995. ARGUMENTS TO FUNCTIONS. Built-In and external functions are limited to a
  9996.  
  9997. maximum of 15 arguments. There is no limit to the number of arguments that may
  9998.  
  9999. be passed to an internal function.
  10000.  
  10001.  
  10002.  
  10003. SUBEXPRESSION NESTING. The maximum nesting level for subexpressions is 32.
  10004.  
  10005.  
  10006.  
  10007. COMPATIBILITY
  10008.  
  10009.  
  10010.  
  10011. ARexx departs in a few ways from the language definition. The differences can
  10012.  
  10013. be classified as omissions or extensions,and are described below.
  10014.  
  10015.  
  10016.  
  10017. OMISSIONS. The only significant specification of the language standard omitted
  10018.  
  10019. from this implementation is the arbitrary-precision arithmetic facility.
  10020.  
  10021. Arithmetic operations are limited to about 14 digits of precision,and the FUZZ
  10022.  
  10023. option is not implemented at all. Only the SCIENTIFIC format is used for
  10024.  
  10025. exponential notation. The full numeric capabilities will be provided in a later
  10026.  
  10027. release.
  10028.  
  10029.  
  10030.  
  10031. EXTENSIONS. The following extensions to the language standard have been
  10032.  
  10033. included in this implementation:
  10034.  
  10035.  
  10036.  
  10037. BREAK INSTRUCTION. A new instruction called BREAK has been implemented. It is
  10038.  
  10039. used to exit from the scope of any DO or INTERPRET instruction.
  10040.  
  10041.  
  10042.  
  10043. ECHO INSTRUCTION. The ECHO instruction has been included as a synonym for SAY.
  10044.  
  10045.  
  10046.  
  10047. SHELL INSTRUCTION. The SHELL instructiion has been included as a synonym for
  10048.  
  10049. ADDRESS.
  10050.  
  10051.  
  10052.  
  10053.                                 109
  10054.  
  10055.  
  10056.  
  10057. SIGNAL OPTIONS. Several additional SIGNAL keywords have been implemented.
  10058.  
  10059. BREAK_C,BREAK_D,BREAK_E,and BREAK_F will detect and trap the control-C through
  10060.  
  10061. control-F signals passed by AmigaDOS. The IOERR keyword traps errors detected
  10062.  
  10063. by the I/O system.
  10064.  
  10065.  
  10066.  
  10067. STEM SYMBOLS. A stem symbol is valid anywhere that a simple symbol could be
  10068.  
  10069. employed.
  10070.  
  10071.  
  10072.  
  10073. TEMPLATE PROCESSING. Templates have been generalized in several ways. Variable
  10074.  
  10075. symbols may be used as positional tokens if preceded by an operator;the "="
  10076.  
  10077. operator is used to denote an absolute position. Multiple templates can be used
  10078.  
  10079. with all source forms of the PARSE instruction.
  10080.  
  10081.  
  10082.  
  10083.                                 110
  10084.  
  10085.  
  10086.  
  10087.                         APPENDIX C THE AREXX SYSTEMS LIBRARY
  10088.  
  10089.  
  10090.  
  10091. The ARexx interpreter is supplied as a shared library named rexxsyslib.library
  10092.  
  10093. and should reside in the system LIBS:directory. While many of the library
  10094.  
  10095. routines are highly specific to the interpreter,some of the functions will be
  10096.  
  10097. useful to applications that use ARexx. The library is opened when the ARexx
  10098.  
  10099. resident process is first loaded and will always be available while it remains
  10100.  
  10101. active.
  10102.  
  10103.  
  10104.  
  10105. The system library routines were designed to be called from assembly-language
  10106.  
  10107. programs and,unless otherwise noted,save all registers except for A0/A1 and
  10108.  
  10109. D0/D1. Many routines return values in more than one register to help reduce
  10110.  
  10111. code size. In addition,the routines will set the condition-code register(CCR)
  10112.  
  10113. wherever appropriate. In mode cases the CCR reflects the value returned in D0.
  10114.  
  10115.  
  10116.  
  10117. The library offsets are defined in the file rxslib.i,which should be INDLUDEd
  10118.  
  10119. in the program source code. Calls may be made from "C" programs if suitable
  10120.  
  10121. binding routines are provided when the program is linked. The definitions for
  10122.  
  10123. the constants and data structures used in ARexx are provided as INCLUDE files
  10124.  
  10125. on the program distribution disk. These should be reviewed carefully before
  10126.  
  10127. attempting to use the library functions.
  10128.  
  10129.  
  10130.  
  10131. FUNCTION GROUPS
  10132.  
  10133. The library functions can be frouped into Conversion,Input/Output,Resource
  10134.  
  10135. Management,and String Manipulation functions.
  10136.  
  10137.  
  10138.  
  10139. DATA CONVERSION. These functions provide many of the common data-conversion
  10140.  
  10141. requirements.
  10142.  
  10143.  
  10144.  
  10145. INPUT/0UTPUT. Two levels of I/O support are provided. The low level functions
  10146.  
  10147. use DOS filehandles directly,while the higher-level functions use linked lists
  10148.  
  10149. of IoBuff structures and support logical file names.
  10150.  
  10151.  
  10152.  
  10153. RESOURCE. These functions allocate,release,or otherwise manage the data
  10154.  
  10155. structures used with ARexx.
  10156.  
  10157.  
  10158.  
  10159. STRING FUNCTIONS. All data in ARexx are managed as strings. These functions
  10160.  
  10161. provide some of the more common string-manipulation operations.
  10162.  
  10163.  
  10164.  
  10165.                                 111
  10166.  
  10167.  
  10168.  
  10169.                 TABLE C.1 AREXX SYSTEMS LIBRARY FUNCTIONS
  10170.  
  10171.  
  10172.  
  10173. NAME            FUNCTIONAL GROUP        DESCRIPTION
  10174.  
  10175. AddClipNode     Resource                Allocate a Clip node
  10176.  
  10177. ClearMem        Resource                Clear a block of memory
  10178.  
  10179. ClearRexxMsg    Resource                Release argstrings from message
  10180.  
  10181. CloseF          Input/Output            Close a file buffer
  10182.  
  10183. ClosePublicPort Resource                Close a port resource node
  10184.  
  10185. CmpString       String                  Compare string structures for equality
  10186.  
  10187. CreateArgstring Resource                Create an argstring structure
  10188.  
  10189. CreateDOSPkt    Input/Output            Creata a DOS Standard Packet
  10190.  
  10191. CreateRexxMsg   Resource                Create a message packet
  10192.  
  10193. CurrentEnv      Resource                Get current storage environment
  10194.  
  10195. CVa2i           Conversion              ASCII to integer
  10196.  
  10197. CVc2x           Conversion              Character to Hex or Binary digits
  10198.  
  10199. CVi2a           Conversion              Integer to ASCII
  10200.  
  10201. CVi2arg         Conversion              Integer to ASCII argstring
  10202.  
  10203. CVi2az          Conversion              Integer to ASCII,leading zeroes
  10204.  
  10205. CVs2i           Conversion              String structure to integer
  10206.  
  10207. CVx2c           Conversion              Hex or binary digits to binary
  10208.  
  10209. DeleteArgstring Resource                Release an argstring structure
  10210.  
  10211. DeleteDOSPkt    Input/Output            Release a DOS Standard Packet
  10212.  
  10213. DeleteRexxMsg   Resource                Release a message packet
  10214.  
  10215. DOSRead         Input/Output            Read from a DOS filehandle
  10216.  
  10217. DOSWrite        Input/Output            Write to a DOS filehandle
  10218.  
  10219. ErrorMsg        Conversion              Get error message from error code
  10220.  
  10221. ExistF          Input/Output            Check whether a DOS file exists
  10222.  
  10223. FillRexxMsg     Resource                Convert and install argstrings
  10224.  
  10225. FindDevice      Input/Output            Locate a DOS device node
  10226.  
  10227. FindRsrcNode    Resource                Locate a resource node
  10228.  
  10229. FreePort        Resource                Close a message port
  10230.  
  10231. FreeSpace       Resource                Release internal memory
  10232.  
  10233. GetSpace        Resource                Allocate internal memory
  10234.  
  10235. InitList        Resource                Initialize a list header
  10236.  
  10237. InitPort        Resource                Initialize a message port
  10238.  
  10239. IsRexxMsg       Resource                Test a message packet
  10240.  
  10241. LengthArgstring Resource                Get length of argstring
  10242.  
  10243. ListNames       Resource                Copy node names to an argstring
  10244.  
  10245. OpenF           Input/Output            Open a file buffer
  10246.  
  10247. OpenPublicPort  Resource                Allocate and open a port resource node
  10248.  
  10249. QueueF          Input/Output            Queue a line in a file buffer
  10250.  
  10251. ReadF           Input/Output            Read from a file buffer
  10252.  
  10253. ReadStr         Input/Output            Read a string from a file buffer
  10254.  
  10255. RemClipNode     Resource                Release a Clip node
  10256.  
  10257. RemRsrcList     Resource                Release a resource list
  10258.  
  10259. RemRsrcNode     Resource                Release a resource node
  10260.  
  10261.  
  10262.  
  10263.                                 112
  10264.  
  10265.  
  10266.  
  10267.                 TABLE C.1 LIBRARY FUNCTIONS (cont)
  10268.  
  10269.  
  10270.  
  10271. NAME            FUNCTIONAL GROUP        DESCRIPTION
  10272.  
  10273. SeekF           Input/Output            Reposition a file buffer
  10274.  
  10275. StackF          Input/Output            Stack a line in a file buffer
  10276.  
  10277. StcToken        String                  Break out a token
  10278.  
  10279. StrcmpN         String                  Compare strings
  10280.  
  10281. StrcpyA         String                  Copy a string,converting to ASCII
  10282.  
  10283. StrcpyN         String                  Copy a string
  10284.  
  10285. StrCpyU         String                  Copy a string,converting to uppercase
  10286.  
  10287. StrflipN        String                  Reverse characters in a string
  10288.  
  10289. Strlen          String                  Find length of a string
  10290.  
  10291. ToUpper         Conversion              ASCII to uppercase
  10292.  
  10293. WriteF          Input/Output            Write to a file buffer
  10294.  
  10295.  
  10296.  
  10297. C-2 LIBRARY FUNCTIONS
  10298.  
  10299. The following descriptions of the ARexx Systems Library functions are listed
  10300.  
  10301. alphabetically. The required arguments and register assignments are shown in
  10302.  
  10303. parentheses after the function name. Multiple returns are shown in parentheses
  10304.  
  10305. on the left-hand side of the call.
  10306.  
  10307.  
  10308.  
  10309. AddClipNode()-allocate and link a Clip node
  10310.  
  10311. Usage:node=AddClipNode(list,name,length,value)
  10312.  
  10313.         D0              A0   A1    D0     D1
  10314.  
  10315.         A0
  10316.  
  10317.        (CCR)
  10318.  
  10319.  
  10320.  
  10321. Allocates and links a Clip node into the specified list. Clip nodes are
  10322.  
  10323. resource nodes containing a name and value string,and include an "auto-delete"
  10324.  
  10325. function for simple maintenance. The list argument must point to a properly-
  10326.  
  10327. initialized EXEC list header. The name argument points to a null-terminated
  10328.  
  10329. name string,the value argument is a pointer to a storage area,and the length
  10330.  
  10331. argument is its length in bytes. The returned value is a pointer to the
  10332.  
  10333. allocated node,or 0 if the allocation failed.
  10334.  
  10335.  
  10336.  
  10337. The RemClipNode()function is installed as the "auto-delete" function for each
  10338.  
  10339. node. Clip nodes can be intermixed with other resource nodes in a list and then
  10340.  
  10341. released with a single call to RemRsrcList().
  10342.  
  10343. See Also:RemClipNode(),RemRsrcList(),RemRsrcNode()
  10344.  
  10345.  
  10346.  
  10347. AddRsrcNode()-allocate and link a resource node
  10348.  
  10349. Usage:node=AddRsrcNode(list,name,length)
  10350.  
  10351.         D0              A0   A1    D0
  10352.  
  10353.         A0
  10354.  
  10355.        (CCR)
  10356.  
  10357.  
  10358.  
  10359. Allocates and links a resource node(a RexxRsrc structure)to the specified list.
  10360.  
  10361. The name argument is a pointer to a null-terminated string,a copy of which is
  10362.  
  10363. installed in the node structure. The length argument is the total length for
  10364.  
  10365. the node;this length is saved within the node so that it may be released later.
  10366.  
  10367.  
  10368.  
  10369.                                 113
  10370.  
  10371.  
  10372.  
  10373. The returned value is a pointer to the allocated node,or 0 if the allocation
  10374.  
  10375. failed.
  10376.  
  10377. See Also:RemRsrcList(),RemRsrcNode()
  10378.  
  10379.  
  10380.  
  10381. ClearMem()-clear a block of memory
  10382.  
  10383. Usage:ClearMem(address,length)
  10384.  
  10385.                 A0       D0
  10386.  
  10387.  
  10388.  
  10389. Clears a block of memory beginning at the given address for the specified
  10390.  
  10391. length in bytes. The address must be word-aligned and the length must be a
  10392.  
  10393. multiple of 4 bytes;all structures allocated by ARexx meet these restrictions.
  10394.  
  10395. Register A0 is preserved.
  10396.  
  10397.  
  10398.  
  10399. ClearRexxMsg()-release argument strings
  10400.  
  10401. Usage:ClearRexxMsg(msgptr,count)
  10402.  
  10403.                     A0     D0
  10404.  
  10405.  
  10406.  
  10407. Releases one or more argstrings from a message packet and clears the
  10408.  
  10409. corresponding slots. The count argument specifies the number of argument slots
  10410.  
  10411. to clear,and can be set to less than 16 to reserve some to the slots for
  10412.  
  10413. private use. No action is taken if the slot already contains a zero value.
  10414.  
  10415. See Also:FillRexxMsg()
  10416.  
  10417.  
  10418.  
  10419. CloseF()-close a file buffer
  10420.  
  10421. Usage:boolean=CloseF(IoBuff)
  10422.  
  10423.         D0             A0
  10424.  
  10425.  
  10426.  
  10427. Release the IoBuff structure and closes the associated DOS file. CloseF()is the
  10428.  
  10429. "auto-delete" function for the IoBuff structure,so an entire list of file
  10430.  
  10431. buffers can be closed with a single call to RemRsrcList().
  10432.  
  10433.  
  10434.  
  10435. ClosePublicPort()-close a port resource node
  10436.  
  10437. Usage:ClosePublicPort(node)
  10438.  
  10439.                        A0
  10440.  
  10441.  
  10442.  
  10443. Unlinks and closes the message port and releases the resource node structure.
  10444.  
  10445. The node must have been allocated by the OpenPublicPort()function.
  10446.  
  10447. See Also:OpenPublicPort()
  10448.  
  10449.  
  10450.  
  10451. CmpString()-compare string structures for equality
  10452.  
  10453. Usage:test=CmpString(ss1,ss2)
  10454.  
  10455.        D0             A0 A1
  10456.  
  10457.       (CCR)
  10458.  
  10459.  
  10460.  
  10461. The arguments ss1 and ss2 must be pointers to ARexx string structures and are
  10462.  
  10463. compared for equality. String structures include the length and hash code of
  10464.  
  10465. the string,so the actual strings are not compared unless the lengths and hash
  10466.  
  10467. codes match. The return value sets the CCR and will be -1(True)if the strings
  10468.  
  10469. match and 0(False)otherwise.
  10470.  
  10471.  
  10472.  
  10473.                                 114
  10474.  
  10475.  
  10476.  
  10477. CreateArgstring()-create an argument string structure
  10478.  
  10479. Usage:argstring=CreateArgstring(string,length)
  10480.  
  10481.           D0                      A0     D0
  10482.  
  10483.           A0
  10484.  
  10485.          (CCR)
  10486.  
  10487.  
  10488.  
  10489. Allocates a RexxArg structure and copies the supplied string into it. The
  10490.  
  10491. argstring return is a pointer to the string buffer of the structure,and can be
  10492.  
  10493. treated like an ordinary string pointer. The RexxArg structure stores the
  10494.  
  10495. structure size and string length at negative offsets to the string pointer. The
  10496.  
  10497. string pointer can be set to NULL if only an uninitialized structure is
  10498.  
  10499. required.
  10500.  
  10501. See Also:DeleteArgstring()
  10502.  
  10503.  
  10504.  
  10505. CreateDOSPkt()-allocate and initialize a DOS standard Packet.
  10506.  
  10507. Usage:packet = CreateDOSPkt()
  10508.  
  10509.        D0
  10510.  
  10511.        A0
  10512.  
  10513.       (CCR)
  10514.  
  10515.  
  10516.  
  10517. Allocates a DOS StandardPacket structure and initializes it by interlinking the
  10518.  
  10519. EXEC message and the DOS packet substructures. No replyport is installed in
  10520.  
  10521. either the message or the packet,as these fields are generally filled in just
  10522.  
  10523. before the message is sent.
  10524.  
  10525. See Also:DeleteDOSPkt()
  10526.  
  10527.  
  10528.  
  10529. CreateRexxMsg()-allocate an ARexx message packet
  10530.  
  10531. Usage: msgptr=CreateRexxMsg(replyport,extension,host)
  10532.  
  10533.          D0                     A0       A1      D0
  10534.  
  10535.          A0
  10536.  
  10537.         (CCR)
  10538.  
  10539.  
  10540.  
  10541. This function allocates an ARexx message packet from the system free memory
  10542.  
  10543. list. The message packet consists of a standard EXEC message structure extended
  10544.  
  10545. to include space for function arguments,returned results,and internal defaults.
  10546.  
  10547. The replyport argument points to a public or private message port and must be
  10548.  
  10549. supplied,as it is required to return the message packet to the sender. The
  10550.  
  10551. extension and host arguments are pointers to null-terminated strings that
  10552.  
  10553. provide values for the default file extension and the initial host address,
  10554.  
  10555. respectively. Additional override fields in the extended packet except for the
  10556.  
  10557. primary and secondary result fields rm_Result1 and rm_Result2.
  10558.  
  10559. See Also: DeleteRexxMsg()
  10560.  
  10561.  
  10562.  
  10563. CVa2i()-convert from ASCII to integer
  10564.  
  10565. Usage: (digits,value) = CVa2i(buffer)
  10566.  
  10567.           D0     D1             A0
  10568.  
  10569.  
  10570.  
  10571. Converts the buffer of ASCII characters to a signed long integer value. The
  10572.  
  10573. scan proceeds until a non-digit character is found or until an overflow is
  10574.  
  10575. detected. The function returns both the number of digits scanned and the
  10576.  
  10577. converted value.
  10578.  
  10579.  
  10580.  
  10581.                                 115
  10582.  
  10583.  
  10584.  
  10585. CVc2x()-convert(unpack)from character string to hex or binary digits.
  10586.  
  10587. Usage: error = CVc2x(outbuff,string,length,mode)
  10588.  
  10589.         D0             A0      A1     D0    D1
  10590.  
  10591.  
  10592.  
  10593. Converts the signed integer value argument to ASCII characters using the
  10594.  
  10595. supplied buffer pointer. The digits argument specifies the maximum number of
  10596.  
  10597. characters that will be copied to the buffer. The returned length is the actual
  10598.  
  10599. number of characters copied. The pointer return is the new buffer pointer.
  10600.  
  10601. See Also: CVi2az()
  10602.  
  10603.  
  10604.  
  10605. CVi2arg()-convert from integer to argstring
  10606.  
  10607. Usage: argstring=CVi2arg(value,digits)
  10608.  
  10609.           D0               D0    D1
  10610.  
  10611.           A0
  10612.  
  10613.          (CCR)
  10614.  
  10615.  
  10616.  
  10617. Converts the signed long integer value argument to ASCII characters,and
  10618.  
  10619. installs them in an argstring(a RexxArg structure). The returned value is an
  10620.  
  10621. argstring pointer or 0 if the allocation failed. The allocated structure can be
  10622.  
  10623. released using DeleteArgstring().
  10624.  
  10625.  
  10626.  
  10627. CVi2az()-convert from integer to ASCII with leading zeroes
  10628.  
  10629. Usage: (length,pointer)=CVi2az(buffer,value,digits)
  10630.  
  10631.           D0      A0            A0     D0    D1
  10632.  
  10633.  
  10634.  
  10635. Converts the signed long integer value argument to ASCII characters in the
  10636.  
  10637. supplied buffer,with leading zeroes to fill out the requested number of digits.
  10638.  
  10639. This function is identical to CVi2a except that leading zeroes are supplied.
  10640.  
  10641. See Also:CVi2a()
  10642.  
  10643.  
  10644.  
  10645. CVs2i()-convert from string structure to integer
  10646.  
  10647. Usage: (error,value)=CVs2i(ss)
  10648.  
  10649.          D0    D1          A0
  10650.  
  10651.  
  10652.  
  10653. The ss argument must be a pointer to a string structure. It is converted to a
  10654.  
  10655. signed long integer value return. The error return code is 47("Arithmetic
  10656.  
  10657. conversion error")if the string is not a valid number.
  10658.  
  10659.  
  10660.  
  10661.                                 116
  10662.  
  10663.  
  10664.  
  10665. CVx2c()-convert from hex or binary digits to(packed)string
  10666.  
  10667. Usage:error=CVx2c(outbuff,string,length,mode)
  10668.  
  10669.        D0           A0      A1     D0    D1
  10670.  
  10671.  
  10672.  
  10673. Converts the string argument of hex(0-9,A-F)or binary(0,1)digits to the packed
  10674.  
  10675. binary representation. The mode argument specifies the(hex or binary)conversion
  10676.  
  10677. mode,and must be set to -1 for hex strings or 0 for binary strings. Blank
  10678.  
  10679. characters may be embedded in the string for readability,but only at byte
  10680.  
  10681. boundaries. The error return code is 47 if the string is not a valid hex or
  10682.  
  10683. binary string.
  10684.  
  10685.  
  10686.  
  10687. CurrentEnv()-return the current storage environment
  10688.  
  10689. Usage:envptr=CurrentEnv(rxtptr)
  10690.  
  10691.         D0                A0
  10692.  
  10693.  
  10694.  
  10695. Returns a pointer to the current storage environment associated with an
  10696.  
  10697. executing ARexx program. The rxptr argument is a pointer to the RexxTask
  10698.  
  10699. structure,and may be obtained from the message packet sent to an external
  10700.  
  10701. application.
  10702.  
  10703.  
  10704.  
  10705. DeleteArgstring()-delete(release)an argstring structure
  10706.  
  10707. Usage:DeleteArgstring(argstring)
  10708.  
  10709.                           A0
  10710.  
  10711.  
  10712.  
  10713. Releases an argstring (RexxArg) structure. The RexxArg structure contains the
  10714.  
  10715. total allocated length at a negative offset from the argstring pointer.
  10716.  
  10717. See Also:CreateArgstring()
  10718.  
  10719.  
  10720.  
  10721. DeleteDOSPkt()-release a DOS Standard Packet structure.
  10722.  
  10723. Usage:DeleteDOSPkt(message)
  10724.  
  10725.                       A0
  10726.  
  10727.  
  10728.  
  10729. Releases a DOS StandardPacket structure,typically obtained by a prior call to
  10730.  
  10731. CreateDOSPkt().
  10732.  
  10733. See Also:CreateDOSPkt()
  10734.  
  10735.  
  10736.  
  10737. DeleteRexxMsg()-delete(release)an ARexx message packet.
  10738.  
  10739. Usage:DeleteRexxMsg(packet)
  10740.  
  10741.                       A0
  10742.  
  10743.  
  10744.  
  10745. Release an ARexx message packet to the system free-memory list. The internal
  10746.  
  10747. MN-LENGTH field is used as the total size of the memory block to be released,so
  10748.  
  10749. this function can be used to release any message packet that contains the total
  10750.  
  10751. length in this field. Any embedded argument strings must be released before
  10752.  
  10753. calling DeleteRexxMsg().
  10754.  
  10755. See Also:CreateRexxMsg()
  10756.  
  10757.  
  10758.  
  10759.                                 117
  10760.  
  10761.  
  10762.  
  10763. DOSREAD()-read from a DOS file
  10764.  
  10765. Usage:count=DOSRead(filehandle,buffer,length)
  10766.  
  10767.         D0              A0       A1     D0
  10768.  
  10769.        (CCR)
  10770.  
  10771.  
  10772.  
  10773. Reads one or more characters from a DOS filehandle into the supplied buffer.
  10774.  
  10775. The length argument specifies the maximum number of characters that will be
  10776.  
  10777. read. The returned count is the actual number of bytes transferred,or -1 if an
  10778.  
  10779. error occurred.
  10780.  
  10781.  
  10782.  
  10783. DOSWrite()-write to a DOS file
  10784.  
  10785. Usage:count=DOSWrite(filehandle,buffer,length)
  10786.  
  10787.        D0               A0        A1     D0
  10788.  
  10789.       (CCR)
  10790.  
  10791.  
  10792.  
  10793. Writes a buffer of the specified length to a DOS filehandle. The retuned count
  10794.  
  10795. is the actual number of bytes written,or -1 if an error occurred.
  10796.  
  10797.  
  10798.  
  10799. ErrorMsg()-find the message associated with an error code
  10800.  
  10801. Usage:(boolean,ss)=ErrorMsg(code)
  10802.  
  10803.           D0   A0            D0
  10804.  
  10805.  
  10806.  
  10807. Returns the error message(as a pointer to a string structure)associated with
  10808.  
  10809. the specified ARexx error code. The boolean return will be -1 if the supplied
  10810.  
  10811. code was a valid ARexx error code,and 0 otherwise.
  10812.  
  10813.  
  10814.  
  10815. ExistF()-check whether an external file exists
  10816.  
  10817. Usage:boolean=ExistF(filename)
  10818.  
  10819.         D0              A0
  10820.  
  10821.        (CCR)
  10822.  
  10823.  
  10824.  
  10825. Tests whether an external file currently exists by attempting to obtain a read
  10826.  
  10827. lock on the file. The boolean return indicates whether the operation succeeded,
  10828.  
  10829. and the lock is released.
  10830.  
  10831.  
  10832.  
  10833. FillRexxMsg()-convert and install arguments in message packet.
  10834.  
  10835. Usage:boolean=FillRexxMsg(msgptr,count,mask)
  10836.  
  10837.         D0                 A0     D0    D1
  10838.  
  10839.  
  10840.  
  10841. This function can be used to convert and install up to 16 argument strings in a
  10842.  
  10843. RexxMsg structure. The message packet must be allocated and the argument fields
  10844.  
  10845. of interest set to either a pointer to a null-terminated string or an integer
  10846.  
  10847. value. The count argument specifies the number of fields,beginning with ARGO,to
  10848.  
  10849. be converted into argstrings and installed into the argument slot. Bits 0-15 of
  10850.  
  10851. the mask argument specify whether the corresponding argument is a string
  10852.  
  10853. pointer(bit clear)or an integer value(bit set).
  10854.  
  10855.  
  10856.  
  10857.                                 118
  10858.  
  10859.  
  10860.  
  10861. The count argument is normally set to the exact number of strings to be passed.
  10862.  
  10863. By setting this count to less than 16,a number of the slots can be reserved for
  10864.  
  10865. private uses.
  10866.  
  10867.  
  10868.  
  10869. The returned value is -1(True)if all of the arguments were successfully
  10870.  
  10871. converted. In the event of an allocation failure,all of the partial results are
  10872.  
  10873. released and a value of 0 is returned.
  10874.  
  10875. See Also:ClearRexxMsg()
  10876.  
  10877.  
  10878.  
  10879. FindDevice()-check whether a DOS device exists.
  10880.  
  10881. Usage:device=FindDevice(devicename,type)
  10882.  
  10883.         D0                  A0      D0
  10884.  
  10885.         A0
  10886.  
  10887.        (CCR)
  10888.  
  10889.  
  10890.  
  10891. Scans the DOS DeviceList for a device node of the specified type matching the
  10892.  
  10893. null-terminated name string. The acceptable values for the type argument are
  10894.  
  10895. the constants DLT_DEVICE,DLT_DIRECTORY,or DLT_VOLUME define in the DOS INCLUDE
  10896.  
  10897. files. Device names are conveted to uppercase before checking for a match. The
  10898.  
  10899. returned value is a pointer to the matched device node,or 0 if the device was
  10900.  
  10901. not found.
  10902.  
  10903.  
  10904.  
  10905. FindRsrcNode()-locate a resource node with the given name.
  10906.  
  10907. Usage:node=FindRsrcNode(list,name,type)
  10908.  
  10909.       D0                 A0   A1   D0
  10910.  
  10911.       A0
  10912.  
  10913.      (CCR)
  10914.  
  10915.  
  10916.  
  10917. Searchs the specified list for the first node of the selected type with the
  10918.  
  10919. given name. The list argument must be a pointer to a properly-initialized EXEC
  10920.  
  10921. list header. The name argument is a pointer to a null-terminated string. If the
  10922.  
  10923. type argument is 0,all nodes are selected;otherwise,the supplied type must
  10924.  
  10925. match the LN_TYPE field of the node. The returned value is a pointer to the
  10926.  
  10927. node or 0 if no matching node was found.
  10928.  
  10929.  
  10930.  
  10931. FreePort()-release resources associated with a message port
  10932.  
  10933. Usage:FreePort(port)
  10934.  
  10935.                 A0
  10936.  
  10937.  
  10938.  
  10939. This function deallocates the signal bit associated with a message port and
  10940.  
  10941. marks the port as "closed." The task calling FreePort()must be the same one
  10942.  
  10943. that initialized the port,since signal bit allocations are specific to a task.
  10944.  
  10945. The memory space associated with the port is not released.
  10946.  
  10947. See Also:InitPort()
  10948.  
  10949.  
  10950.  
  10951. FreeSpace()-releases space to the internal memory allocator.
  10952.  
  10953. Usage:FreeSpace(envptr,block,length)
  10954.  
  10955.                   A0     A1    D0
  10956.  
  10957.  
  10958.  
  10959. Returns a block of memory to the internal allocator,which must have been
  10960.  
  10961. obtained from a call to GetSpace(). The envptr argument is a pointer to the
  10962.  
  10963. base or current storage environment.
  10964.  
  10965. See Also:CurrentEnv(),GetSpace()
  10966.  
  10967.  
  10968.  
  10969.                                 119
  10970.  
  10971.  
  10972.  
  10973. GetSpace()-allocate memory using the internal allocator.
  10974.  
  10975. Usage:block=GetSpace(envptr,length)
  10976.  
  10977.        D0              A0     D0
  10978.  
  10979.        A0
  10980.  
  10981.       (CCR)
  10982.  
  10983.  
  10984.  
  10985. Allocates a block of memory using the internal allocator. The memory is
  10986.  
  10987. obtained from an internal pool managed by the interpreter and is returned to
  10988.  
  10989. the operating system when the ARexx program terminates. The envptr argument is
  10990.  
  10991. a pointer to the base or current storage environment for the program.
  10992.  
  10993.  
  10994.  
  10995. The internal allocator must be used to allocate strings for use as values for
  10996.  
  10997. symbols,and is convenient for obtaining small blocks of memory whose lifetime
  10998.  
  10999. will not exceed that of the ARexx program.
  11000.  
  11001. See Also:CurrentEnv(),FreeSpace()
  11002.  
  11003.  
  11004.  
  11005. InitList()-initialize a list header
  11006.  
  11007. Usage:InitList(list)
  11008.  
  11009.                 A0
  11010.  
  11011.  
  11012.  
  11013. Initializes an EXEC list header structure.
  11014.  
  11015.  
  11016.  
  11017. InitPort()-initialize a previously-allocated message port.
  11018.  
  11019. Usage:(signal,port)=InitPort(port,name)
  11020.  
  11021.          D0    A1             A0   A1
  11022.  
  11023.  
  11024.  
  11025. Initializes a message port structure for which memory space has been previously
  11026.  
  11027. allocated,typically as part of a larger structure or as static storage in a
  11028.  
  11029. program. It installs the task ID(of the task calling the function)into the
  11030.  
  11031. MP_SIGTASK field and allocates a signal bit. The name parameter must be a
  11032.  
  11033. pointer to a null-terminated string. The signal return is the signal bit that
  11034.  
  11035. was allocated for the port. In the event that a signal could not be assigned,a
  11036.  
  11037. value of -1 is returned.
  11038.  
  11039.  
  11040.  
  11041. Note that the port is not linked into the system Ports List. If the port is to
  11042.  
  11043. be made public,this can be done after the function returns. The port address is
  11044.  
  11045. returned in the correct register(A1)for a subsequent call to the EXEC function
  11046.  
  11047. AddPort().
  11048.  
  11049. See Also:FreePort()
  11050.  
  11051.  
  11052.  
  11053. IsRexxMsg()-check whether a message came from ARexx.
  11054.  
  11055. Usage:boolean=IsRexxMsg(msgptr)
  11056.  
  11057.          D0               A0
  11058.  
  11059.  
  11060.  
  11061. Tests whether the message packet specified by the msgptr argument came from an
  11062.  
  11063. ARexx program. ARexx marks its messages with a pointer to a static string
  11064.  
  11065. "REXX" in the LN_NAME field. The returned value is either -1(True)if the
  11066.  
  11067. message came from ARexx or 0(False)otherwise.
  11068.  
  11069.  
  11070.  
  11071.                                 120
  11072.  
  11073.  
  11074.  
  11075. IsSymbol()-check whether a string is a valid symbol.
  11076.  
  11077. Usage:(code,length)=IsSymbol(string)
  11078.  
  11079.         D0    D1               A0
  11080.  
  11081.  
  11082.  
  11083. Scans the supplied string pointer for ARexx symbol characters. The code return
  11084.  
  11085. is the symbol type if a symbol was found,or 0 if the string did not start with
  11086.  
  11087. a symbol character. The length return is the total length of the symbol.
  11088.  
  11089.  
  11090.  
  11091. ListNames()-build a string of names from a list.
  11092.  
  11093. Usage:argstring=ListNames(list,separator)
  11094.  
  11095.          D0                A0   D0[0:7]
  11096.  
  11097.          A0
  11098.  
  11099.         (CCR)
  11100.  
  11101.  
  11102.  
  11103. Scans the specified list and copies the name strings into an argstring. The
  11104.  
  11105. list argument must be a pointer to an initialized EXEC list header. The
  11106.  
  11107. separator argument is the character,possibly a null,to be placed as a delimiter
  11108.  
  11109. between the node names.
  11110.  
  11111.  
  11112.  
  11113. The list is traversed inside a Forbid()exclusion and so may be used with shared
  11114.  
  11115. or system lists. The returned argstring can be released using DeleteArgstring()
  11116.  
  11117. after the names are no longer needed.
  11118.  
  11119. See Also:DeleteArgstring()
  11120.  
  11121.  
  11122.  
  11123. LockRexxBase()-lock a shared resource.
  11124.  
  11125. Usage:LockRexxBase(resource)
  11126.  
  11127.                       D0
  11128.  
  11129.  
  11130.  
  11131. Secures the specified resource in the ARexx Systems Library base for read
  11132.  
  11133. access. The resource argument is a manifest constant for the required resource,
  11134.  
  11135. or zero to lock the entire structure.
  11136.  
  11137.  
  11138.  
  11139. Note that write access to shared resources is normally mediated by the ARexx
  11140.  
  11141. resident process,which operates at an elevated priority to gain exclusive
  11142.  
  11143. access. Locking a resource should not be attempted from a process operating at
  11144.  
  11145. a priority higher than the resident process.
  11146.  
  11147. See Also:UnlockRexxBase()
  11148.  
  11149.  
  11150.  
  11151. OpenF()-open a file buffer
  11152.  
  11153. Usage:IoBuff=OpenF(list,filename,mode,logical)
  11154.  
  11155.         D0          A0    A1      D0     D1
  11156.  
  11157.         A0
  11158.  
  11159.        (CCR)
  11160.  
  11161.  
  11162.  
  11163. Attempts to open an external file in the specified mode,which should be one of
  11164.  
  11165. the constants RXIO_READ,RXIO_WRITE,or RXIO_APPEND defined in the ARexx INCLUDE
  11166.  
  11167. files.
  11168.  
  11169.  
  11170.  
  11171.                                 121
  11172.  
  11173.  
  11174.  
  11175. If successful,an IoBuff structure is allocated and linked into the specified
  11176.  
  11177. list. The list argument must be a pointer to a properly-initialized EXEC list
  11178.  
  11179. header.
  11180.  
  11181.  
  11182.  
  11183. The optional logical argument is the logical name for the file,and must be
  11184.  
  11185. either a pointer to a null-terminated string or zero(NULL)if a name is not
  11186.  
  11187. required.
  11188.  
  11189. See Also:CloseF()
  11190.  
  11191.  
  11192.  
  11193. OpenPublicPort()-open a public message port
  11194.  
  11195. Usage:node=OpenPublicPort(list,name)
  11196.  
  11197.        D0                  A0   A1
  11198.  
  11199.        A0
  11200.  
  11201.       (CCR)
  11202.  
  11203.  
  11204.  
  11205. Allocates a message port as an "auto-delete" resource node and links it into
  11206.  
  11207. the specified list. The list argument must point to a properly initialized EXEC
  11208.  
  11209. list header. The message port is initialized with the given name and linked
  11210.  
  11211. into the system Ports List.
  11212.  
  11213. See Also:ClosePublicPort()
  11214.  
  11215.  
  11216.  
  11217. QueueF()-queue a line to a file buffer.
  11218.  
  11219. Usage:count-=QueueF(IoBuff,buffer,length)
  11220.  
  11221.         D0            A0     A1     D0
  11222.  
  11223.  
  11224.  
  11225. Queues a buffer of characters in the stream associated with the IoBuff
  11226.  
  11227. structure. The stream must be managed by a DOS handler that supports the
  11228.  
  11229. ACTION_QUEUE packet.
  11230.  
  11231.  
  11232.  
  11233. Queued lines are placed in "first-in,first-out" order and are immediately
  11234.  
  11235. available to be read from the stream. The buffer argument is a pointer to a
  11236.  
  11237. string of characters,and the length specifies the number of characters to be
  11238.  
  11239. queued. The return value is the actual count of characters or -1 if an error
  11240.  
  11241. occurred.
  11242.  
  11243. See Also:StackF()
  11244.  
  11245.  
  11246.  
  11247. ReadF()-read characters from a file buffer
  11248.  
  11249. Usage:count=ReadF(IoBuff,buffer,length)
  11250.  
  11251.        D0           A0     A1     D0
  11252.  
  11253.       (CCR)
  11254.  
  11255.  
  11256.  
  11257. Reads one or more characters from the file specified by the IoBuff pointer. The
  11258.  
  11259. buffer argument is a pointer to a storage area,and the length argument
  11260.  
  11261. specifies the maximum number of characters to be read. The return value is the
  11262.  
  11263. actual number of characters read,or -1 if an error occurred.
  11264.  
  11265.  
  11266.  
  11267. ReadStr()-read a string from a file
  11268.  
  11269. Usage:(count,pointer)=ReadStr(IoBuff,buffer,length)
  11270.  
  11271.         D0     A1               A0     A1     D0
  11272.  
  11273.  
  11274.  
  11275. Reads characters from the file specified by the IoBuff pointer until a
  11276.  
  11277. "newline" character is found. The "newline" is not included in the returned
  11278.  
  11279. string. The return value is the actual number of characters read,or -1 if an
  11280.  
  11281. error occurred.
  11282.  
  11283.  
  11284.  
  11285.                                 122
  11286.  
  11287.  
  11288.  
  11289. See Also:ReadF()
  11290.  
  11291.  
  11292.  
  11293. RemClipNode()-unlink and deallocate a list Clip node.
  11294.  
  11295. Usage:RemClipNode(node)
  11296.  
  11297.                    A0
  11298.  
  11299.  
  11300.  
  11301. Unlinks and releases the specified Clip node. The function is the "auto-delete"
  11302.  
  11303. function for Clip nodes,and will be called automatically by RemRsrcNode() or
  11304.  
  11305. RemRsrcList().
  11306.  
  11307. See Also:AddClipNode(),RemRsrcList(),RemRsrcNode()
  11308.  
  11309.  
  11310.  
  11311. RemRsrcList()-unlink and deallocate a list of resource nodes
  11312.  
  11313. Usage:RemRsrcList(list)
  11314.  
  11315.                    A0
  11316.  
  11317.  
  11318.  
  11319. Scans the supplied list and releases any nodes found. The list must consist of
  11320.  
  11321. resource nodes(RexxRsrc structures),which contain information to allow
  11322.  
  11323. automatic cleanup and deletion.
  11324.  
  11325. See Also:RemRsrcNode()
  11326.  
  11327.  
  11328.  
  11329. RemRsrcNode()-unlink and deallocate a resource node
  11330.  
  11331. Usage:RemRsrcNode(node)
  11332.  
  11333.                    A0
  11334.  
  11335.  
  11336.  
  11337. Unlinks and releases the specified resource node,including the name string if
  11338.  
  11339. one is present. If an "auto-delete" function has been specified in the node,it
  11340.  
  11341. is called to perform any required resource deallocation before the node is
  11342.  
  11343. released.
  11344.  
  11345. See Also:RemRsrcList()
  11346.  
  11347.  
  11348.  
  11349. SeekF()-seek to the specified position in a file.
  11350.  
  11351. Usage:position=SeekF(IoBuff,offset,anchor)
  11352.  
  11353.         D0             A0    D0      D1
  11354.  
  11355.  
  11356.  
  11357. Seeks to a new position in the file is specified by the IoBuff pointer. The
  11358.  
  11359. position is given by the offset argument,a byte offset relative to the supplied
  11360.  
  11361. anchor argument. The anchor may specify the beginning(-1),the current position
  11362.  
  11363. (0),or the end of the file(1). The return value is the new position relative to
  11364.  
  11365. the beginning of the file.
  11366.  
  11367.  
  11368.  
  11369. StackF()-stack a line to a file buffer.
  11370.  
  11371. Usage:count=StackF(IoBuff,buffer,length)
  11372.  
  11373.         D0           A0     A1     D0
  11374.  
  11375.  
  11376.  
  11377. Stacks a buffer of characters in the stream associated with the IoBuff
  11378.  
  11379. structure. The buffer argument is a pointer to a string of characters,and the
  11380.  
  11381. length specifies the number of characters to be stacked. The return value is
  11382.  
  11383. the actual count of characters to be stacked. The return value is the actual
  11384.  
  11385. count of characters or -1 if an error occurred.
  11386.  
  11387.  
  11388.  
  11389.                                 123
  11390.  
  11391.  
  11392.  
  11393. Stacked lines are placed in "last-in,first-out" order and are immediately
  11394.  
  11395. available to be read from the stream. The stream must be managed by a DOS
  11396.  
  11397. handler that supports the ACTION_STACK packet.
  11398.  
  11399. See Also:QueueF()
  11400.  
  11401.  
  11402.  
  11403. StcToken()-break out the next token from a string
  11404.  
  11405. Usage:(quote,length,scan,token)=StcToken(string)
  11406.  
  11407.         D0     D1    A0   A1               A0
  11408.  
  11409.  
  11410.  
  11411. Scans a null-terminated string to select the next token delimited by "white
  11412.  
  11413. space,"and returns a pointer to the start of the token. The quote return will
  11414.  
  11415. be an ASCII single or double quote if the token was quoted and 0 otherwise;
  11416.  
  11417. white space characters are ignored within quoted strings. The length return is
  11418.  
  11419. the total length of the token,including any quote characters. The scan return
  11420.  
  11421. is advanced beyond the current token to prepare for the next call.
  11422.  
  11423.  
  11424.  
  11425. StrcpyA()-copy a string,converting to ASCII
  11426.  
  11427. Usage:hash=StrcpyA(destination,source,length)
  11428.  
  11429.        D0              A0        A1     D0
  11430.  
  11431.  
  11432.  
  11433. Copies the source string to the destination area,converting the characters to
  11434.  
  11435. ASCII by clearing the high-order bit of each byte. The length of the string
  11436.  
  11437. (which may include embedded nulls)is considered as a 2-byte usingned integer.
  11438.  
  11439. So the string is limited in length to 65,535 bytes. The hash return is the
  11440.  
  11441. internal hash byte for the copied string.
  11442.  
  11443. See Also:StrcpyN(),StrcpyU
  11444.  
  11445.  
  11446.  
  11447. StrcpyN()-copy a string
  11448.  
  11449. Usage:hash=StrcpyN(destination,source,length)
  11450.  
  11451.        D0              A0        A1     D0
  11452.  
  11453.  
  11454.  
  11455. Copies the source string to the destination area. The length of the string
  11456.  
  11457. (which may include embedded nulls)is considered as a 2-byte unsigned integer.
  11458.  
  11459. The hash return is the internal hash byte for the copied string.
  11460.  
  11461. See Also:StrcpyA(),StrcpyU
  11462.  
  11463.  
  11464.  
  11465. StrcpyU()-copy a string,converting to uppercase
  11466.  
  11467. Usage:hash=StrcpyU(destination,source,length)
  11468.  
  11469.        D0               A0       A1     D0
  11470.  
  11471.  
  11472.  
  11473. Copies the source string to the destination area,converting to uppercase
  11474.  
  11475. alphabetics. The length of the string(which may include embedded nulls)is
  11476.  
  11477. considered as a 2-byte unsigned integer. The has return is the internal hash
  11478.  
  11479. byte for the copied string.
  11480.  
  11481. See Also:StrcpyA(),StrcpyN
  11482.  
  11483.  
  11484.  
  11485.                                 124
  11486.  
  11487.  
  11488.  
  11489. StrflipN()-reverse the characters in a string
  11490.  
  11491. Usage:StrflipN(string,length)
  11492.  
  11493.                  A0     D0
  11494.  
  11495.  
  11496.  
  11497. Reverses the sequence of characters in a string. The conversion is performed in
  11498.  
  11499. place.
  11500.  
  11501.  
  11502.  
  11503. Strlen()-find the length of a null-terminated string
  11504.  
  11505. Usage:length=Strlen(string)
  11506.  
  11507.         D0            A0
  11508.  
  11509.        (CCR)
  11510.  
  11511.  
  11512.  
  11513. Returns the number of characters in a null-terminated string. Register A0 is
  11514.  
  11515. preserved,and the CCR is set for the returned length.
  11516.  
  11517.  
  11518.  
  11519. StrcmpN()-compare the values of strings
  11520.  
  11521. Usage:test=StrcmpN(string1,string2,length)
  11522.  
  11523.        D0             A0      A1     D0
  11524.  
  11525.       (CCR)
  11526.  
  11527.  
  11528.  
  11529. The string1 and string2 arguments are compared for the specified number of
  11530.  
  11531. characters. The comparison proceeds character-by-character until a difference
  11532.  
  11533. is found or the maximum number of characters have been examined. The returned
  11534.  
  11535. value is -1 if the first string was less,1 if the first string was greater,and
  11536.  
  11537. 0 if the strings match exactly. The CCR register is set for the returned value.
  11538.  
  11539.  
  11540.  
  11541. ToUpper()-translate an ASCII character to uppercase
  11542.  
  11543. Usage:upper=ToUpper(character)
  11544.  
  11545.        D0               D0
  11546.  
  11547.  
  11548.  
  11549. Converts an ASCII character to uppercase. Only register D0 is affected.
  11550.  
  11551.  
  11552.  
  11553. UnlockRexxBase()-unlock a shared resource.
  11554.  
  11555. Usage:UnlockRexxBase(resource)
  11556.  
  11557.                         D0
  11558.  
  11559.  
  11560.  
  11561. Releases the specified resource,or all resources if the argument is zero. Every
  11562.  
  11563. call to LockRexxBase()should be followed eventually by a call to UnlockRexxBase
  11564.  
  11565. ()for the same resource.
  11566.  
  11567. See Also:LockRexxBaseF()
  11568.  
  11569.  
  11570.  
  11571. WriteF()-write characters to a file buffer
  11572.  
  11573. Usage:count=WriteF(IoBuff,buffer,length)
  11574.  
  11575.         D0          A0      A1     D0
  11576.  
  11577.        (CCR)
  11578.  
  11579.  
  11580.  
  11581. Writes a buffer of characters of the specified length to the file associated
  11582.  
  11583. with the IoBuff pointer. The buffer argument is a pointer to a storage area,
  11584.  
  11585.  
  11586.  
  11587.                                 125
  11588.  
  11589.  
  11590.  
  11591. and the length argument specifies the number of characters to be written. The
  11592.  
  11593. returned value is the actual number of characters written or -1 if an error
  11594.  
  11595. occurred.
  11596.  
  11597. See Also:CloseF(),OpenF(),ReadF()
  11598.  
  11599.  
  11600.  
  11601.                                 126
  11602.  
  11603.  
  11604.  
  11605.                 APPENDIX D THE AREXX SUPPORT LIBRARY
  11606.  
  11607.  
  11608.  
  11609. The ARexx language system is distributed with an external function library that
  11610.  
  11611. provides a number of Amiga-specific functions. It is a standard Amiga shared
  11612.  
  11613. library named rexxsupport.library and should reside in the system
  11614.  
  11615. LIBS:directory. Unlike the Systems Library described in the previous
  11616.  
  11617. Appendix,the support library functions are callable from within ARexx programs.
  11618.  
  11619.  
  11620.  
  11621.  
  11622.  
  11623. ALLOCMEM()
  11624.  
  11625. Usage:ALLOCMEM(length,[attribute])
  11626.  
  11627. Allocates a block of memory of the specified length from the system free-
  11628.  
  11629. memory pool and returns its address as a 4-byte string. The optional attribute
  11630.  
  11631. parameter must be a standard EXEC memory allocation flag,supplied as a 4-byte
  11632.  
  11633. string. The default attribute is for "PUBLIC" memory(not cleared).
  11634.  
  11635.  
  11636.  
  11637. This function should be used whenever memory is allocated for use by external
  11638.  
  11639. programs. It is the user's responsibility to release the memory space when it
  11640.  
  11641. is no longer needed.
  11642.  
  11643. See Also:FREEMEM()
  11644.  
  11645. Example:
  11646.  
  11647.         say c2x(allocmem(1000)) ==>00050000
  11648.  
  11649.  
  11650.  
  11651. CLOSEPORT()
  11652.  
  11653. Usage:CLOSEPORT(name)
  11654.  
  11655. Closes the message port specified by the name argument,which must have been
  11656.  
  11657. allocated by a call to OPENPORT()within the current ARexx program. Any messages
  11658.  
  11659. received but not yet REPLYed are automatically returned with the return code
  11660.  
  11661. set to 10.
  11662.  
  11663. See Also:OPENPORT()
  11664.  
  11665. Example:
  11666.  
  11667.         call closeport myport
  11668.  
  11669.  
  11670.  
  11671.                                 127
  11672.  
  11673.  
  11674.  
  11675. FREEMEM()
  11676.  
  11677. Usage:FREEMEM(address,length)
  11678.  
  11679. Releases a block of memory of the given length to the system freelist. The
  11680.  
  11681. address parameter is a four-byte string,typically obtained by a prior call to
  11682.  
  11683. ALLOCMEM(). FREEMEM()cannot be used to release memory allocated using
  11684.  
  11685. GETSPACE(),the ARexx internal memory allocator. The returned value is a boolean
  11686.  
  11687. success flag.
  11688.  
  11689. See Also:ALLOCMEM()
  11690.  
  11691. Example:
  11692.  
  11693.         say freemem('00042000'x,32)     ==>1
  11694.  
  11695.  
  11696.  
  11697. GETARG()
  11698.  
  11699. Usage:GETARG(packet,[n])
  11700.  
  11701. Extracts a command,function name,or argument string from a message packet. The
  11702.  
  11703. packet argument must be a 4-byte address obtained from a prior call to
  11704.  
  11705. GETPKT(). The optional n argument specifies the slot containing the string to
  11706.  
  11707. be extracted,and must be less than or equal to the actual argument count for
  11708.  
  11709. the packet. Commands and functions names are always in slot 0;function packets
  11710.  
  11711. may have argument strings in slots 1-15.
  11712.  
  11713. Examples:
  11714.  
  11715.         command = getarg(packet)
  11716.  
  11717.         function= getarg(packet,0)      /* name string  */
  11718.  
  11719.         arg1    = getarg(packet,1)      /* 1st argumeent*/
  11720.  
  11721.  
  11722.  
  11723. GETPKT()
  11724.  
  11725. Usage:GETPKT(name)
  11726.  
  11727. Checks the message port specified by the name argument to see whether any
  11728.  
  11729. messages are available. The named message port must have been opened by a prior
  11730.  
  11731. call to OPENPORT() within the current ARexx program. The returned value is the
  11732.  
  11733. 4-byte address of the first message packet,or '0000 0000'x if no packets were
  11734.  
  11735. available.
  11736.  
  11737.  
  11738.  
  11739. The function returns immediately whether or not a packet is enqueued at the
  11740.  
  11741. message port. Programs should never be designed to "busy-loop" on a message
  11742.  
  11743. port. If there is no useful work to be done until the next message packet
  11744.  
  11745. arrives,the program should call WAITPKT()and allow other tasks to proceed.
  11746.  
  11747. See Also:WAITPKT()
  11748.  
  11749. Example:
  11750.  
  11751.         packet = getpkt('MyPort')
  11752.  
  11753.  
  11754.  
  11755. OPENPORT()
  11756.  
  11757. Usage:OPENPORT(name)
  11758.  
  11759. Creates a public message port with the given name. The returned value is the
  11760.  
  11761. 4-byte address of the Port Resource strcture or '0000 000'xif the port could
  11762.  
  11763. not be opened or initialized. An initialization failure will occur if another
  11764.  
  11765. port of the same name already exists,or if a signal bit couldn't be allocated.
  11766.  
  11767.  
  11768.  
  11769.                                 128
  11770.  
  11771.  
  11772.  
  11773. The message port is allocated as a Port Resource node and is linked into the
  11774.  
  11775. program's global data structure. Ports are automatically closed when the
  11776.  
  11777. program exits,and any pending messages are returned to the sender.
  11778.  
  11779. See Also:CLOSEPORT()
  11780.  
  11781. Example:
  11782.  
  11783.         myport = openport("MyPort")
  11784.  
  11785.  
  11786.  
  11787. REPLY()
  11788.  
  11789. Usage:REPLY(packet,rc)
  11790.  
  11791. Returns a message packet to the sender,with the primary result field set to the
  11792.  
  11793. value given by the rc argument. The secondary result is cleared. The packet
  11794.  
  11795. argument must be supplied as a 4-byte address,and the rc argument must be a
  11796.  
  11797. whole number.
  11798.  
  11799. Example:
  11800.  
  11801.         call reply packet,10            /* error return*/
  11802.  
  11803.  
  11804.  
  11805. SHOWDIR()
  11806.  
  11807. Usage:SHOWDIR(directory,['All' | 'File' | 'Dir'])
  11808.  
  11809. Returns the contents of the specified directory as a string of names separated
  11810.  
  11811. by blanks. The second parameter is an option keyword that selects whether all
  11812.  
  11813. entries,only files,or only subdirectories will be included.
  11814.  
  11815. Example:
  11816.  
  11817.         say showdir("df1:c")            ==>rx ts te hi tco tcc
  11818.  
  11819.  
  11820.  
  11821. SHOWLIST()
  11822.  
  11823. Usage:SHOWLIST[{'D' | 'L' | 'P' | 'R' | 'W' },[name])
  11824.  
  11825. The first argument is an option keyword to select a system list;the options
  11826.  
  11827. currently supported are Devices,Libraries,Ports,Ready,and Waiting. If only the
  11828.  
  11829. first parameter is supplied,the function scans the selected list and returns
  11830.  
  11831. the node names in a string separated by blanks. If the name parameter is
  11832.  
  11833. supplied,the boolean return indicates whether the specified list contains a
  11834.  
  11835. node of that name. The name matching is case-sensitive.
  11836.  
  11837.  
  11838.  
  11839. The list is scanned with task switching forbidden so as to provide an accurate
  11840.  
  11841. snapshot of the list at that time.
  11842.  
  11843. Example:
  11844.  
  11845.         say showlist('P')               ==>REXX MyCon
  11846.  
  11847.         say showlist('P','REXX')        ==>1
  11848.  
  11849.  
  11850.  
  11851.                                 129
  11852.  
  11853.  
  11854.  
  11855. STATEF()
  11856.  
  11857. Usage:STATEF(filename)
  11858.  
  11859. Returns a string containing information about an external file. The string is
  11860.  
  11861. formatted as   "{DIR | FILE} length blocks protection comment."
  11862.  
  11863. The length token gives the file length in bytes,and the block token specifies
  11864.  
  11865. the file length in blocks.
  11866.  
  11867. Example:
  11868.  
  11869.         say statef("libs:rexxsupport.library")
  11870.  
  11871.         /* would give "FILE 1880 4 RWED "       */
  11872.  
  11873.  
  11874.  
  11875. WAITPKT()
  11876.  
  11877. Usage:WAITPKT(name)
  11878.  
  11879. Waits for a message to be received at the specified(named)port,which must have
  11880.  
  11881. been opened by a call to OPENPORT() within the current ARexx program. The
  11882.  
  11883. returned boolean value indicates whether a message packet is available at the
  11884.  
  11885. port. Normally the returned value will be 1(True),since the function waits
  11886.  
  11887. until an event occurs at the message port.
  11888.  
  11889.  
  11890.  
  11891. The packet must then be removed by a call to GETPKT(),and should be returned
  11892.  
  11893. eventually using the REPLY()function. Any message packets received but not
  11894.  
  11895. returned when an ARexx program exits are automatically REPLYed with the return
  11896.  
  11897. code set to 10.
  11898.  
  11899. Example:
  11900.  
  11901.         call waitpkt 'MyPort'   /* wait awhile  */
  11902.  
  11903.  
  11904.  
  11905.                                 130
  11906.  
  11907.  
  11908.  
  11909.                         APPENDIX E DISTRIBUTION FILES
  11910.  
  11911.  
  11912.  
  11913. This appendix lists the directores of the standard ARexx distribution disk. The
  11914.  
  11915. contents of some of the directories may change from time to time,so your disk
  11916.  
  11917. may not show exactly the same files. Most notably,the :rexx directory will
  11918.  
  11919. expand as more program examples are included in it.
  11920.  
  11921.  
  11922.  
  11923. The second section of the Appendix lists the HEADER files that define the
  11924.  
  11925. constants and data structures used with ARexx. All of these files are available
  11926.  
  11927. in the :INCLUDE directory,but are listed here for convenience in studying the
  11928.  
  11929. structures.
  11930.  
  11931.  
  11932.  
  11933. DIRECTORIES
  11934.  
  11935.  
  11936.  
  11937. The files are listed below as they would be using the system dir command. For
  11938.  
  11939. example,"dir df1:c opt a" would list the contents of the :c directory on disk
  11940.  
  11941. drive 1.
  11942.  
  11943.  
  11944.  
  11945. THE :C DIRECTORY
  11946.  
  11947.  
  11948.  
  11949. This directory contains the command utilities used with ARexx. These files
  11950.  
  11951. should be copied to your system C: directory when you install the program.
  11952.  
  11953.  
  11954.  
  11955.                 c(dir)
  11956.  
  11957.                 hi                      loadlib
  11958.  
  11959.                 rexxmast                rx
  11960.  
  11961.                 rxc                     rxset
  11962.  
  11963.                 tcc                     tco
  11964.  
  11965.                 te                      ts
  11966.  
  11967.  
  11968.  
  11969. THE :INCLUDE DIRECTORY
  11970.  
  11971.  
  11972.  
  11973. This directory has the INCLUDE and HEADER files used for assembly language and
  11974.  
  11975. "C" programming,respectively. These files contain the structure definitions
  11976.  
  11977. necessary to build an interface to ARexx.
  11978.  
  11979.  
  11980.  
  11981.                 include(dir)
  11982.  
  11983.                 errors.h                rexxio.h
  11984.  
  11985.                 rxslib.h                storage.h
  11986.  
  11987.                 errors.i                rexxio.i
  11988.  
  11989.                 rxslib.i                storage.i
  11990.  
  11991.  
  11992.  
  11993.                                 131
  11994.  
  11995.  
  11996.  
  11997. THE :LIBS DIRECTORY
  11998.  
  11999.  
  12000.  
  12001. These are the library files for the language interpreter and the Support
  12002.  
  12003. Library functions. Both files should be copied to your system LIBS:directory
  12004.  
  12005. when you install ARexx.
  12006.  
  12007.  
  12008.  
  12009.                 libs(dir)
  12010.  
  12011.                 rexxsupport.library     rexxsyslib.library
  12012.  
  12013.  
  12014.  
  12015.  
  12016.  
  12017.  
  12018.  
  12019.   This rather long but comprehensive Tutorial by: South West Amiga Group 1991
  12020.  
  12021.  
  12022.